Jump to content

Recommended Posts

Can you update form fields with the same id's if the are in divs that are set to hidden?

 

Semantically, an ID is a unique identifier, so, logically, there shouldn't be two elements with the same ID anywhere on your page.  So, no, you wouldn't be able to use document.getElementById() on them.

 

What you can do is access the elements by their names:

<script type="text/javascript">
   window.onload = function()
   {
      var input1 = document.forms["myForm"].elements["input1"];
      var input2 = document.forms["myForm"].elements["input2"];

      input1.value = "something";
      input2.value = "something else";
   }
</script>
</head>

<body>

<form name="myForm" action="#" method="post">
   <input name="input1" type="text" /><br />
   <input name="input2" type="text" />
</form>

</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.