Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Synthax troubles

Status
Not open for further replies.

ronnie98

Technical User
Aug 5, 2004
36
IT
Hi all,
i have this code:


Code:
var popupSrc = document.getElementById("f_url").value;

var popupTitle = document.getElementById("poptitle").value;


html = "<a href=javascript:myPopImage(";

html += "'" + popupSrc + "',";

html += "'" + popupTitle + "'";

html += ")>";

where "f_url" and "poptitle" are text fields.
It should always output:

Code:
<a href=javascript:myPopImage('[URL unfurl="true"]http://www.sampleurl.com/image.jpg','Popuptitle')">[/URL]

but it stops working if the value of "poptitle" field is made of
more than one word,like:

Code:
<a href=javascript:myPopImage('[URL unfurl="true"]http://www.sampleurl.com/image.jpg','My[/URL] Popup Title')">

It seems that the space(s) between 2 or more words inside "poptitle" field
affects and breaks the synthax of the code producing stange outputs like:

Code:
<a href=javascript:myPopImage('[URL unfurl="true"]http://www.sampleurl.com/image.jpg','My)">[/URL]

so it truncates the value to the first word.
I need some help,of course.
Where i am wrong?
Thanks in advance,ralf.
 
Your code is not quoting the content of the href tag, which is a fault. Your displayed examples also then display an unmatched double quote at the tail end of the href content which your code doesn't even generate. I suspect your browser may be getting lost interpreting the code you're inserting (if that's what you're doing). Try:
Code:
html = "<a href=\"javascript:myPopImage('" + popupSrc + "','" + popupTitle + "')\">";
 
Thank you very much MOrac,
it works perfectly now!:)
ATB,ronnie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top