SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing the string variables through a form

    hello all,

    I have a simple form and i want to pass the results of the form to other page but I get in other page "undefined" value back.

    Can u look at the script and tell me what is wrong:

    passingVariables.html

    <html>
    <head>
    </head>

    <BODY>
    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    firstname = unescape(params["firstname"]);
    lastname = unescape(params["lastname"]);
    age = unescape(params["age"]);

    document.write("firstname = " + firstname + "<br>");
    document.write("lastname = " + lastname + "<br>");
    document.write("age = " + age + "<br>");
    // End -->
    </script>
    <center>
    <form type=get action="passing-values-source.html">
    <table border=1>
    <tr>
    <td>First Name/td>
    <td><input type=text name=firstname size=10></td>
    </tr>
    <tr>
    <td>Last Name/td>
    <td><input type=text name=lastname size=10></td>
    </tr>
    <tr>
    <td>Age/td>
    <td><input type=text name=age size=3></td>
    </tr>
    <tr>
    <td colspan=2><input type=submit value="Submit!">
    </td>
    </tr>
    </table>
    </form>
    </center>
    </html>
    on this page i am passing the variable to passing-values-source.html:
    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">

    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->

    <!-- Begin
    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();
    // End -->
    </script>
    </HEAD>
    <body>
    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    firstname = unescape(params["firstname"]);
    lastname = unescape(params["lastname"]);
    age = unescape(params["age"]);

    document.write("firstname = " + firstname + "<br>");
    document.write("lastname = " + lastname + "<br>");
    document.write("age = " + age + "<br>");
    // End -->
    </script>

    </body>

    </html>

    what am i doing wrong?

    thanx

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    New Jersey
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The script works fine...if you open it via a web server...if you just have the files on your desktop it and double-click on passingVariables.html to open it it wont work...try uploading the file to a webserver(or install apache on your computer) and it should work with no problems...


Bookmarks

Posting Permissions

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