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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing "" to function

Status
Not open for further replies.

michelledebeer

Programmer
Oct 26, 2001
22
0
0
SE
I would like to pass quotes ("") into a function.
I have tried escaping them with \", but all I get is "undetermined string constant".
Without the quotes, all is well.

function printQuotes(html) {
alert(html);
}
...
<body onload=&quot;javascript:printQuotes('<a href=&quot;link.htm&quot;>thelink</a>');&quot;>

Any thoughts?
// Michelle
 
Try escaping the quotes this way :

<body onload=&quot;printQuotes('<a href=\&quot;link.htm\&quot;>thelink</a>');&quot;>

BTW : the javascript: pseudo protocol is useless here.
Gary Haran
 
Try escaping the quotes with HTML rather than javascript. That should do the trick.


<body onload=&quot;printQuotes('<a href=&quot;link.htm&quot;>thelink</a>');&quot;>
 
Of course remembering that this site will translate the HTML escape would help.



<body onload=&quot;printQuotes('<a href=& quot;link.htm& quot;>thelink</a>');&quot;>

Just take out the space between & and quot.
 
Thanks...

I would like to follow up with another question:
If I pass this to the function:
<body onload=&quot;printQuotes('<a href=& quot;link.htm& quot;>thelink</a>');&quot;>

Can I in the function replace the & quot; to &quot; instead, perhaps using regular expressions?
(Pseudo-code)
function printQuotes(html) {
// Replace & quot; with &quot; in html
quotedHtml = replaceInString('& quot;', '&quot;', html);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top