Click to See Complete Forum and Search --> : Parse HTML POST arguments from JavaScript


BradleyRan
01-15-2003, 10:40 AM
Hi All,

I would like to pass some arguments to a JavaScript on another HTML page like:

http://www.my.site/MarkerList.html?Species=cattle&Chromosome=1

I see the "document.URL" contains the information I need and I just wondered if there was an easy or standard way to parse it out.

Thanks,

Randy

khalidali63
01-15-2003, 10:44 AM
typically url contains
? = that means the data starts from here
& mean the next data element

And you usually have to parse it depending upon the way data is passed from the form.

hope this helps

Khalid

AdamGundry
01-15-2003, 10:46 AM
When data is passed on the URL, it is using GET (not POST). I once wrote a script to automatically parse GET fields on the URL, using regular expressions, but unfortunately I've lost it now. The variable window.location.search holds the GET query as a string, starting with ? and delineated by &, as Khalid said.

I'm not sure if there are any pre-written scripts available out there, but you might be able to find one instead of writing your own code.

Adam

BradleyRan
01-15-2003, 11:13 AM
Thanks. I guess its easy enough:

url = document.URL.split("?")

args = url[1].split("&")
arg1 = args[0].split("=")
arg2 = args[1].split("=")

document.write(arg1[0] + " = " + arg1[1] + "<p>")
document.write(arg2[0] + " = " + arg2[1] + "<p>")

Now I just need to add my preprocessing stuff with a couple of if blocks.

Randy

jeffmott
01-15-2003, 12:26 PM
args = url[1].split("&")
Remember that the semi-colon can also delimit a name/value pair.

args = url[1].split(/[&;]/)