www.webdeveloper.com
Results 1 to 6 of 6

Thread: reference value of hidden input in form

  1. #1
    Join Date
    Feb 2004
    Posts
    5

    Question reference value of hidden input in form

    Hi

    I'm trying to change the value of a hidden input field in a form when another button is clicked.

    Something like,

    <html>

    <head>
    <script type=Javascript>
    function updateValue()
    { document.all.test.blah.value = 2;
    }

    </script>
    </head>

    <body>
    <form name=test>

    <INPUT name=blah type=text value=0>

    </form>

    <img src=em.gif onCLick=updateValue()>

    </body>

    </html>

    I knew how to do this once but just can't remember what the proper way to reference it through the document is.

    Any help is much appreciated.

    Thanks

  2. #2
    Join Date
    Dec 2003
    Location
    Dallas, Texas
    Posts
    256
    Try using:

    document.test.blah.value = 2;

    vs.

    document.all.test.blah.value = 2;

  3. #3
    Join Date
    Feb 2004
    Posts
    5
    Thanks that worked

    BUt the actual problem was that I had
    type=Javascript instead of type = JavaScript

    How stupid!

    Any way now I have a new set of problems. I want to pass the name of the element as a parameter of the function like this.

    <html>

    <head>
    <script type=text/JavaScript>
    function updateValue(name)
    { document.test.name.value = 2;
    }

    </script>
    </head>

    <body>
    <form name=test method=get>

    <INPUT name=blah type=text value=0>

    </form>

    <img src=em.gif onClick=updateValue(blah)>

    </body>

    </html>

    Howver this does not work.
    Do I have to change the variable name in some way before I can use it?

    Or maybe I have to pass the parameter differently?

  4. #4
    Join Date
    Dec 2003
    Location
    Dallas, Texas
    Posts
    256
    You can use this instead:

    document.getElementById(name).value = 2;

    vs.

    document.test.name.value = 2;

    Just make sure to put quotes around blah in the call, i.e.:

    <img src=em.gif onClick=updateValue('blah')>

  5. #5
    Join Date
    Feb 2004
    Posts
    5
    Yes,

    that works perfectly!

    It's actually part of a much bigger project, so i hope it works just as well there as in my little test.

    thanks again!

  6. #6
    Join Date
    Dec 2003
    Location
    Dallas, Texas
    Posts
    256
    You're welcome.

    Glad I could help.

Thread Information

Users Browsing this Thread

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

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