Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Pass Variable from URL to HTM File

    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

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Spain
    Posts
    420
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>
    Last edited by Borgtex; 01-11-2003 at 05:36 PM.
    Don't resist to assimilation. Billions of Borgs can't be wrong!

  • #3
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Cannot get code to work

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •