Click to See Complete Forum and Search --> : encoding url


Webskater
01-28-2003, 04:16 AM
I am reading the value of a control on a form and concatenating it to a querystring. How should I encode it so that if the string contains special characters or quotation marks etc it does not get truncated or fall over?

function whatever()
{
var UsersReason = formname.fieldname.value
location.replace('Somepage.htm?Reason=' + UsersReason
}

What should I put round the UsersReason variable to make sure it makes it to the server without being affected. Thanks for any answers.

Charles
01-28-2003, 04:40 AM
escape()

See http://developer.netscape.com/docs/manuals/js/client/jsref/toplev.htm#1063743.

Webskater
01-28-2003, 05:13 AM
Thanks for your reply.
When the string gets to the server do you have to use unescape() to remove hex characters added to the string to replace quotation marks etc.?

Charles
01-28-2003, 05:28 AM
Not the JavaScript function unescape() but use whatever un-escaping function or method is available server side.