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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to pass variables from one form to another using Javascript?

    I am trying to creat a two-part form using client side scripting only. The form would require the user to fill out certain information on the first page before being allowed to view the other sections of the form on the second page.

    I have the validation down and am trying to pass the parameters into the URL of the next page which I am doing successfully. The problem I am having is getting the URL variables to display on the next page. They are writing out as "undefined".

    I have included both pages of code I am using below as one of you may be able to point out my mistake. Thanks for taking the time to help an intermediate programmer...


    First page code:

    <head>
    <title>Room Reservation and Catering Form</title>

    <SCRIPT LANGUAGE="JavaScript">

    function checkrequired(which) {
    var pass=true;
    if (document.images) {
    for (i=0;i<which.length;i++) {
    var tempobj=which.elements[i];
    if (tempobj.name.substring(0,8)=="required") {
    if (((tempobj.type=="text"||tempobj.type=="textarea")&&
    tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
    tempobj.selectedIndex==0)) {
    pass=false;
    break;
    }
    }
    }
    }
    if (!pass) {
    shortFieldName=tempobj.name.substring(8,30).toUpperCase();
    alert("Please make sure the "+shortFieldName+" field was properly completed.");
    return false;
    }
    else
    return true;
    }

    </script>

    </head>

    <body>

    <form onSubmit="return checkrequired(this)" type=get action="RoomReservationForm2.html">

    <table width="100%" align="center" valign="top" cellpadding="0" cellsapcing="0" border="0">

    <tr>
    <td colspan="3" align="center"><font face="arial" size="3"><b><i>Children's Medical Center Dallas</i><br>Room Reservation Form</b><br><br></font></td>
    </tr>

    <tr align="center">
    <td align="left" width="30%"><input type="text" name="requiredlastname" value="" size="15" maxlength="25"><br><font face="arial" size="2">Last name</font></td>
    <td align="left" width="30%"><input type="text" name="requiredfirstname" value="" size="15" maxlength="25"><br><font face="arial" size="2">First name</font></td>
    <td align="left" width="30%"><input type="text" name="requiredphone" value="" size="15" maxlength="25"><br><font face="arial" size="2">Phone extension</font></td>
    </tr>
    <tr>
    <td colspan="3"><input type=submit value="Submit"></td>
    </tr>

    </table>

    </form>
    </body>




    Second page code:

    <head>
    <title>Room Reservation and Catering Form 2</title>

    <SCRIPT LANGUAGE="JavaScript">

    function getParams() {
    var idx = document.URL.indexOf('?');
    var params = new Array();
    if (idx != -1) {
    var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
    for (var i=0; i<pairs.length; i++) {
    nameVal = pairs[i].split('=');
    params[nameVal[0]] = nameVal[1];
    }
    }
    return params;
    }
    params = getParams();

    </script>
    </head>

    <body>
    <SCRIPT LANGUAGE="JavaScript">

    requiredlastname = unescape(params["requiredlastname"]);
    requiredfirstname = unescape(params["requiredfirstname"]);
    requiredphone = unescape(params["requiredphone"]);

    document.write("requiredlastname = " + requiredlastname + "<br>");
    document.write("requiredfirstname = " + requiredfirstname + "<br>");
    document.write("requiredphone = " + requiredphone + "<br>");

    </script>
    </body>

  • #2
    Regular Coder
    Join Date
    Dec 2002
    Location
    the windy city
    Posts
    140
    Thanks
    0
    Thanked 0 Times in 0 Posts
    see this tutorial


  •  

    Posting Permissions

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