#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Manchester, England
    Posts
    11
    Rep Power
    0

    Javascript: Hidden values


    I have a Javascript that sets the value of a text box based on the screen resolution.

    This works fine, but i'd like the text box hidden...

    I have tried doing it with a hidden value but the value is not altered.

    <input name="field" type="text">
    form.field.value = "hello";

    works.

    but....
    <input name="field" type="hidden">
    form.field.value = "hello";

    doesnt!!!

    Any ideas?
  2. #2
  3. An Ominous Coward
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2002
    Posts
    4,425
    Rep Power
    0
    What browser? For it to work on non-broken browsers you'll need:
    Code:
    document.form.field.value = "foo";
    Of course... I'm assuming you also have a form tag with a name='form' attribute, since it's not shown here
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Manchester, England
    Posts
    11
    Rep Power
    0
    Yeah, I do have the form name value, ;o)

    For some reason, browsers dont seem to like changing the value of a hidden form field.

    Is there any way round this other than using a text box?

    You see i have a script to detect the screen res, and want to pass that onto my php script which sets it as a cookie.

    EDIT: PS: Just been looking around DevShed (my saviour as always) and it seems that this move was intentional in JScript to stop malicious use... Any other ideas on how to retain a value through a page but not having to use an editable text box?
    Last edited by Bix; December 28th, 2002 at 03:39 AM.
  6. #4
  7. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, you could set the visibility of the text box to hidden. style="visibility:hidden;". You might try making the field disabled, too. I'm not sure if it will submit with the rest of the form then, though.
    -james
  8. #5
  9. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    This code works fine.

    Code:
    <html>
    <body>
    <form method="get" name="theform">
    	<input type="hidden" name="hideme" />
    	<input type="submit" />
    </form>
    <script type="text/javascript">
    document.theform.hideme.value = 'hello';
    </script>
    </body>
    </html>
    -james
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Manchester, England
    Posts
    11
    Rep Power
    0
    The above doesnt seem to work in IE or Mozilla.
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Manchester, England
    Posts
    11
    Rep Power
    0
    Originally posted by bricker42
    Well, you could set the visibility of the text box to hidden. style="visibility:hidden;". You might try making the field disabled, too. I'm not sure if it will submit with the rest of the form then, though.
    Cheers buddy, think you've hit the nail on the head there!!!

    Thanks!

    EDIT:

    No, still no luck, I guess browsers don't like hidden fields!
    Last edited by Bix; December 29th, 2002 at 01:27 AM.
  14. #8
  15. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    I have a feeling the problem is with your server-side script. The following code works in Mozilla 1.2.1, Phoenix 0.5, and IE 5.0 on Win2k. Check the url after you hit submit. The last thing on there with be "?hideme=hello2".
    Code:
    <html>
    <body>
    <form method="get" name="theform">
    	<input type="hidden" name="hideme" />
    	<input type="submit" />
    </form>
    <script type="text/javascript">
    document.theform.hideme.value = 'hello';
    alert( document.theform.hideme.value );
    document.theform.hideme.value = 'hello2';
    alert( document.theform.hideme.value );
    </script>
    </body>
    </html>
    -james
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Manchester, England
    Posts
    11
    Rep Power
    0
    Originally posted by bricker42
    I have a feeling the problem is with your server-side script. The following code works in Mozilla 1.2.1, Phoenix 0.5, and IE 5.0 on Win2k. Check the url after you hit submit. The last thing on there with be "?hideme=hello2".
    Code:
    <html>
    <body>
    <form method="get" name="theform">
    	<input type="hidden" name="hideme" />
    	<input type="submit" />
    </form>
    <script type="text/javascript">
    document.theform.hideme.value = 'hello';
    alert( document.theform.hideme.value );
    document.theform.hideme.value = 'hello2';
    alert( document.theform.hideme.value );
    </script>
    </body>
    </html>
    Jackpot!!!

    Cheers buddy!

    I owe you a beer!

    I never thought to check that it passed on, my fault.

    ;o)
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    El Paso, TX
    Posts
    4
    Rep Power
    0
    I'm trying to do that same thing. I have the screen resolution script (javascript output through PHP), and I got it into a variable, but I can't seem to get it to go through to the next page to be written to the cookie. How did you solve that?

IMN logo majestic logo threadwatch logo seochat tools logo