Link to home
Start Free TrialLog in
Avatar of Stoke
Stoke

asked on

Using URL variables in JS

I have a script (test.htm) and want to use variables in the url with it to call an external page.
I'd call test.htm like this:  test.htm?YOB=2006&strSEX=F&SAL=A

Here's my script so far:

<SCRIPT LANGUAGE="JavaScript">
<!-- Hide from old browsers
// Modify to reflect site specifics
mainserver = "http://example.com/jserver";
target = "/TARGET=/AAMSZ=MULTIPLE/DOB=" + URL.YOB + "/SEX=" + URL.strSEX + "/SALARY=" + URL.SAL;

// Cache-busting and pageid values
random = Math.round(Math.random() * 100000000);
if (!pageNum)
var pageNum = Math.round(Math.random() * 100000000);
document.write('<scr');
document.write('ipt src="' + mainserver + '/acc_random=' + random + target + "/pageid=" + pageNum + '">');
document.write('</scr');
document.write('ipt>');
// End Hide -->
</script>

How do I access the URL variables and how do I default them to 0 if they don't exist in the URL I pass?

Thank you for your time and help.
ASKER CERTIFIED SOLUTION
Avatar of geordie007
geordie007

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stoke
Stoke

ASKER

Thanks. That's great. It's helped me a lot.