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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    140
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Query Strings & Forms

    I have a simple form that accepts input into a text box, passes it to another html page using method="get" and displays the input on the screen to be verified before actual submission.

    I have no probem getting the information to pass to the 2nd page, but I am not sure how I can get that information to actually be submitted.

    Here is my code:

    Page1 - this sends the info in the textbox to Page2.
    Code:
    <html>
    <head>
    <title></title>
    </head>
    
    <body>
    
    <form name="myform" method="get" action="page2.html">
    Enter Name: <input type="text" name="input1">
    <input type="submit">
    </form>
    
    </body>
    </html>

    Page2 - this receives the input reading it from the address bar and displays it on the page.
    Code:
    <html>
    <head>
    <title></title>
    
    <script LANGUAGE="JavaScript">
    function decodeSearchString() {
       var nameValue = new Array();
       var searchStr = unescape(location.search.substring(1));
       if (searchStr) {
           var formElement = searchStr.split("&");
           var tmpArray = new Array();
           for (k = 0; k < formElement.length; k++) {
                tmpArray = formElement[k].split("=");
                nameValue[tmpArray[0]] = tmpArray[1];
           }
       }
       return nameValue
    }
    
    var srchData = decodeSearchString();
    </SCRIPT>
    </head>
    
    <body>
    
    <form name="myform" method="post" action="WHATEVER">
    <input type="hidden" name="subject" value="My Form">
    <input type="hidden" name="next_url" value="WHATEVER">
    
    <script>document.write(srchData.input1.replace(/\+/g, ' '));</script>
    <input type="submit">
    </form>
    
    </body>
    </html>
    I cannot get the value of input1 to be submitted. I only receive the subject = My Form.

    Any suggestions?

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    document.getElementById('hiddenInputElement').value = theValuePassedByURL;
    Of course, this should all be done via server-side scripting.
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).

  • #3
    Regular Coder
    Join Date
    Jan 2005
    Posts
    140
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    What goes in the place of hiddenInputElement and theValuePassedByURL?

    Code:
    document.getElementById('hiddenInputElement').value = theValuePassedByURL;

  • #4
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    <input type="hidden" id="hiddenInputElement" name="hiddenInputElement" value="">
    
    <script type="text/javascript">
    	document.getElementById('hiddenInputElement').value = decodeSearchString();
    </script>
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).

  • #5
    Regular Coder
    Join Date
    Jan 2005
    Posts
    140
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great! That worked, but I do have some more questions.

    The whole point in me having to use query strings is because the client that I am working on a site for does not pay for PHP as part of their hosting package, otherwise I would have used it.

    To me this seems pretty straight forward, send info using a form and have your results displayed to you to verify and have the option to make changes or to submit. What other options are there to do this besides PHP or ASP?

    Yes the solution you told me does work, however it does not work in older browsers that do not support getElementById.

    Are there other options besides cookies? I am not familiar with cookies at all to use them as a solution, your thoughts?

  • #6
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Um. If you don't have server-side scripting capabilities, what are you going to do with the form?
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).

  • #7
    Regular Coder
    Join Date
    Jan 2005
    Posts
    140
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    The form is just going to be submitted like any other form, the receiver would get the results of the form sent to them in an email.

    I just want to be able to have the person filling out the form, in this particular case a simple order form, be able to view the information to verify it's accurancy and have a chance to go back and make any corrections and resubmit.

  • #8
    Regular Coder
    Join Date
    Jan 2005
    Posts
    140
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think I found an alternative to using:
    Code:
    <script type="text/javascript">
    document.getElementById('input1').value = srchData.input1.replace(/\+/g, ' ');
    </script>
    Alternative:
    Code:
    <script type="text/javascript">
    document.myform['input1'].value = srchData.input1.replace(/\+/g, ' ');
    </script>


  •  

    Posting Permissions

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