SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Synthax troubles
-
Feb 15, 2005, 02:54 #1
- Join Date
- Aug 2004
- Location
- Italy
- Posts
- 21
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Synthax troubles
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 += ")>";
It should always output:
Code:<a href=javascript:myPopImage('http://www.sampleurl.com/image.jpg','Popuptitle')">
more than one word,like:
Code:<a href=javascript:myPopImage('http://www.sampleurl.com/image.jpg','My Popup Title')">
affects and breaks the synthax of the code producing stange outputs like:
Code:<a href=javascript:myPopImage('http://www.sampleurl.com/image.jpg','My)">
I need some help,of course.
Where i am wrong?
Thanks in advance,ralf.
-
Feb 15, 2005, 05:41 #2
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I use the following simple function to avoid troubles when building long formatted strings in javascript:
Code:function sprintf(format) { var args = sprintf.arguments, i = 1; return format.replace(/%s/g, function() { return args[i++]; }); }
Code:html = sprintf( "<a href=javascript:myPopImage('%s', '%s')>", popupSrc, popupTitle);
-
Feb 15, 2005, 08:57 #3
- Join Date
- Aug 2004
- Location
- Italy
- Posts
- 21
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you,
i'll try and let you know.
Bookmarks