www.webdeveloper.com
Results 1 to 2 of 2

Thread: accessing hidden field

  1. #1
    Join Date
    Nov 2010
    Posts
    4

    accessing hidden field

    Hello,
    Here is some sample code from my html page:
    <script language="javascript" type="text/javascript">
    function setProperties(formElement)
    {
    formElement.form.elements["customerID"].value=1;
    alert(formElement.form.elements["customerID"].value);


    }
    </script>

    <form name="myform" action="...">
    <input type="hidden" name="customerID" id="customerID" value="xxx">
    <input type="submit" id="loadform" name="loadform" onClick="setProperties(this);" value="Load form"></input>
    <input type="submit" id="process" name="process" value="process"></input>
    </form>
    There are two submit buttons and I would like to change the hidden field value for one of the buttons when it is clicked. I have tried various ways to assign a value to the hidden field in the javascript but none of them works including the above.
    I have tried "formElement.form.customerID.value", "formElement.form.getElementById("customerID"); etc but it does not work. Can someone please guide as to the right way of assigning the hidden field value in javascript. Thanks for your help.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    document.getElementById("customerID").value = 'foo';
    At least 98% of internet users' DNA is identical to that of chimpanzees

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