www.webdeveloper.com
Results 1 to 6 of 6

Thread: How can I carry a value forward from one web page to another

  1. #1
    Join Date
    Nov 2009
    Posts
    7

    How can I carry a value forward from one web page to another

    I have been searching, without success so far, for a script that will allow me to carry a value forward from one web page to another.

    In the first I have a text entry field iName

    In the second I have a text entry field os1

    Is it possible to carry forward the value of iName and have it automatically entered as the value of os1 on the second page? I don't need to show it on the page but I do want the value to be transmitted when the form is 'posted'.

    I fear my Javascript knowledge is very much beginner so if this is a simple thing to do I apologise, but I can't fathom it!

  2. #2
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,143
    Typically you pass information through an HTML form and post the data to a server side language such as PHP. Here's a basic example:

    http://www.w3schools.com/php/php_forms.asp

    You passing data through the form to the php page which grabs the submitted values and can do whatever you need.

  3. #3
    Join Date
    Mar 2010
    Posts
    2,803
    If your form's method = POST then the form's action page will receive th form data in $_POST. If the method = GET then the form data will be received in $_GET.

    Alternatively, if you do not use form submission to transfer data to another page, you can either append a query string of name/value pairs to the destination url or use cookies.

  4. #4
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    If your form's method = POST then the form's action page will receive th form data in $_POST. If the method = GET then the form data will be received in $_GET.
    Don't forget, if the form method=GET, then not only can the server-side language get the data, but JavaScript can get the data from the URL parameters (aka NVP) that are used in place of a POST submission.

    Play around with this:

    Code:
    function getURLandNVP() {
        var thisURL = document.URL;
        var arrayURL = new Array();
            arrayURL = thisURL.split("/");
        var arrayLen = arrayURL.length;
        var thisDelim = "/";
        var thisPath = "";
        var thisNVP = "";
        var qs = false;
        var nvp, thisPart, pre, sp;
        for(i=3; i<arrayLen; i++) {
            thisPart = arrayURL[i];
            thisPartLen = thisPart.length;
            nvp = thisPart.indexOf("?");
            sp = thisPart.indexOf(".");
            if((nvp == -1) && (!qs)) { // If NO URL parameters, add to path
                thisPath += thisDelim + thisPart;
                }
            else if((nvp > -1) && (!qs)) { // If URL parameters, get path and separate from URL parameters
                pre = thisPart.substring(0,nvp);
                thisPath += thisDelim + pre;
                thisNVP = thisPart.substring(nvp+1,thisPartLen);
                thisNVP = thisNVP.replace("&","\n","all");
                }
            else if((sp > -1) && (!qs)) { // If using slash delimiter after document name
                qs = true;
                thisPath += thisDelim + thisPart;
                }
            else if(qs) {
                thisNVP += "\n" + thisPart;
                }
            }
        var thisAlert = thisPath; if(thisNVP.length != 0) { thisAlert += "\nwith NVP of\n" + thisNVP; }
        alert(thisAlert);
        }
    Once this is in the head of a page and you have onLoad="getURLandNVP();" in the body tag, go to that page, then add the following to the URL:
    ?a=1&b=2&c=3&d=I&#37;20like%20NVP
    and click the GO button. You'll get an alert that shows you all the information after the document name.

    ^_^

  5. #5
    Join Date
    Nov 2009
    Posts
    7
    Quote Originally Posted by cbVision View Post
    Typically you pass information through an HTML form and post the data to a server side language such as PHP. Here's a basic example:

    http://www.w3schools.com/php/php_forms.asp
    .
    Thanks, I thought this would be the best place to start but no matter what I try I can't even get their basic example to work!

    The HTML page displays the form correctly, but when I then click on 'Submit Query' the welcome.php file opens with the far from encouraging message: "The server encountered an unexpected condition which prevented it from fulfilling the request.
    The script had an error or it did not produce any output. If there was an error, you should be able to see it in the error log."

    Before anyone asks, yes my server does support PHP4 and PHP5.

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by trenoweth View Post
    Thanks, I thought this would be the best place to start but no matter what I try I can't even get their basic example to work!

    The HTML page displays the form correctly, but when I then click on 'Submit Query' the welcome.php file opens with the far from encouraging message: "The server encountered an unexpected condition which prevented it from fulfilling the request.
    The script had an error or it did not produce any output. If there was an error, you should be able to see it in the error log."

    Before anyone asks, yes my server does support PHP4 and PHP5.
    That is a generic type of error. Could be almost anything related with the access to/within the server-side issues. Check first if you have permissions to send queries on that site / directory / folder / file. If you can access the errors.log file on the server, do it. You will find there details about the error.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles