...

View Full Version : Pass Variable from URL to HTM File



gtfotakis
01-11-2003, 05:05 PM
I am having problem with the below script. I am trying to pass variables from a URL to a .HTM file ...... Please Help!

Passed URL
Dartrep_setupn.htm?projname=GARY1&testeridx=GENPOP01&cycassn=JANC4">

Code Javascript:
function getVar(name) {
var url1 = unescape(this.location.href);

var url2 = url1.split("?");
var url23 = url2[1];
if(url23 != undefined) {

var url3 = url23.split("&");

for (var loop=0; loop < url3.length; loop++)
{
var curVar = url3[loop];
var varSplit = curVar.split("=");
var varName = varSplit[0];
var varValue = varSplit[1];
if(varName = name)
return varValue;
}
return null;
}

}

</script>
</head>
<body>

<SCRIPT LANGUAGE="JavaScript">

document.write("<b><font color=black>Project=<font
color=blue>");document.write(getVar("project"));

document.write("<br><b><font color=black>Report ID=<font
color=blue>");document.write(getVar("testeridx"));

document.write("<br><b><font color=black>Cycle Assigned=<font
color=blue");document.write(getVar("assgncyc"));

</script>

Problem: .. It repeats the GARY1 in Project and Report ID and Cycle Assigned does get displayed

OUTPUT

Report View For -
Project=GARY1
Report ID=GARY1
Cycle Assigned=


Any help would be appreaciated !! Thanks
Thomas

Borgtex
01-11-2003, 05:31 PM
There's a better solution: create real variables first:

<head>
<script>
params=this.location.search.substring(1).split('&')
for (t=0;t<params.length;t++)
{
newvar=params[t].split('=')
eval(newvar[0]+'="'+newvar[1]+'"')
}
</script>
</head>

<body>

<b><font color=black>Project=<font color=blue>
<script>document.write(project);</script>
</font></font></b>

</body>

gtfotakis
01-13-2003, 12:05 AM
Borgtex
I get syntax errors on the JavaScript and when I try to pass the below URL in cannot find the page ... Please review your code sent

thanks

Dartrep_setupn.htm?Projname=GARY1&testeridx=GENPOP01&cycassn=JANC4

also, will this allow me to send multiple variables seperated by the & sign

Thanks

Thomas



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum