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 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Hidden form variables

    Could someone look at this tutorial and tell me how to change the output to the second page so the values are put into hidden form fields? The example we are intereste in using is the Location.search property. We want to pass the form variables to a new page which will have the variables hidden in a new form.
    Thanks......

    Here's the URL:

    http://www.javascriptkit.com/javatutors/send1.shtml

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,030
    Thanks
    0
    Thanked 247 Times in 244 Posts
    the code is still the same.
    you just make the field hidden, instead of type text.

    <input type="hidden" NAME="MyValue" SIZE="12" VALUE="HELLO">
    <input type="hidden" NAME="MyTest" SIZE="15">

    if the type attribute is not present in the <input> tag, the default type is text which is a normal textbox.

  • #3
    New Coder
    Join Date
    Apr 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for replying Glenn.

    I tried that before, changing the type to hidden. But it does not actually place the hidden variable on the page.
    If I look at the page source, they are not there, but if I look at the page info, or page properties in IE, they do show up.
    How can I get the variables to actually show in the source, or does it really matter when I go to use the hidden variables in the next operation by submitting the form on page 2?

    Maybe PHP would be better for this?

    Bruce

  • #4
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    PHP would be better, but you can get the same result with javascript. If you change the value of a hidden formfield, it won't change the HTML if you view the source, but it WILL change the value.

    <html>

    <head>
    <script language="javascript">
    function hidden_value(myform){
    myform.myfield.value=100;
    alert("The value of my hidden field is "+ myform.myfield.value +" but the HTML didn\'t change");
    }
    </script>
    </head>
    <body>
    <form onsubmit="return hidden_value(this);">
    <input type="hidden" name="myfield">
    <input type="submit">
    </form>
    </body>
    </html>

  • #5
    New Coder
    Join Date
    Apr 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did some testing and it does work!
    It will even pass the values to a different server or domain, which is what we need.
    Even though the values don't show in the source HTML, they are passed to the new page or form.
    This eliminates the need to use cookies, as we only need this to happen once.
    Thanks for the input!

    Bruce


  •  

    Posting Permissions

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