Click to See Complete Forum and Search --> : ampersant ("&") in string
How can I get an ampersant ("&") in a string when using javascript? When I try to include "&" in a string, internet explorer reports errors. I want to call an asp page, with a querystring attached to it. In the querystring variables are seperated by an "&". So it's crucial that I can include the "&"!
Post the code you are using... You are probably going to want to replace it with the hexadecimal characters instead. & = %26 in Hex...
The user has to click on a row of a table-object. The values located in the cells are to be included in the querystring of the asp page.
First of al, I build the querystring in javascript, and try to concatenate an "&" to seperate the variables:
querystring += value + "&" //this for each cell (except the last one)
//then, I cal the asp page:
window.open("asppage.aspx?" + querystring)
Internet Explorer errors on the "&" within the string...
Try this:
querystring += value + "&" //this for each cell (except the last one)
//escape the code (turn special characters to their hexadecimal equivalent
querystring = escape(querystring);
//then, I cal the asp page:
window.open("asppage.aspx?" + querystring);
The escape() method doesn't seem to do the job :(
Internet Explorer still reports the error:
"A name was started with an invalid character. Error processing resource"
Even the line:
query=escape("&")
errors in IE :confused:
I forgot to mension: my javascript is located in an xsl stylesheet, but I don't think that makes any difference...
Try one more thing...
querystring += value + "&" //this for each cell (except the last one)
//escape the code (turn special characters to their hexadecimal equivalent
querystring = escape(querystring);
//then, I cal the asp page:
window.open("asppage.aspx?" + escape(querystring));
Negative :(
It has something to do with the xsl stylesheet.
If I try the code in an ordinary html file, I can print the query string, even if I do query="&", without the escape() method.
Weird... But I already have an alternative: using another character, for example the pipe ("|"), and parsing the querystring by hand in the asp page. To bad for the ampersant :(
But thanx anywhay!
Originally posted by Yoda
To bad for the ampersantActually, an ampersand is probably not the best way to do it anyway, as ampersands in your links will not pass the W3C validator -- you have to use &'s