Jump to content

[SOLVED] Updating Fields


tobeyt23

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.