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/D OB=" + 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.
I'd call test.htm like this: test.htm?YOB=2006&strSEX=F
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/D
// 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER