Click to See Complete Forum and Search --> : Form cannot cope with &'s


Rik Comery
06-21-2004, 03:43 AM
Hi. I have built a form which submits the results to a database. All the values of the form are filled out by the user, with the exception of one. This field, i would like to to be the URL of the form. (The page is dynamic, so the address could be one of several posibilities).

Here is the bit that i am having trouble with.
<form name="form">
<input type="hidden" name="address1" value="">
</form>

<script>
document.form.address1.value=document.location
</script>

This works fine, until the URL contains an &. Once the form is submitted, the page thinks that the & signifies the next field.

Is there some way around this?

Ultimately, i would like a URL submitted to the database, that resembles the following:

www.something.com/file.htm?param1=true&param2=false

Tage
06-21-2004, 03:53 AM
You might be able to use encodeURIComponent() (http://msdn.microsoft.com/library/en-us/script56/html/js56jsmthfencodeuri.asp) and decodeURIComponent() (http://msdn.microsoft.com/library/en-us/script56/html/js56jsmthdecodeuricomponent.asp) in some way?
Although, if the user disables/doesn't have javascript it won't send you the address. Maybe you could use a server-side script to do this instead.

Tage