tobeyt23 Posted June 16, 2008 Share Posted June 16, 2008 Can you update form fields with the same id's if the are in divs that are set to hidden? Link to comment https://forums.phpfreaks.com/topic/110491-solved-updating-fields/ Share on other sites More sharing options...
KevinM1 Posted June 16, 2008 Share Posted June 16, 2008 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> Link to comment https://forums.phpfreaks.com/topic/110491-solved-updating-fields/#findComment-566876 Share on other sites More sharing options...
tobeyt23 Posted June 17, 2008 Author Share Posted June 17, 2008 Thank you, that is what I was trying to tell a coworker. Link to comment https://forums.phpfreaks.com/topic/110491-solved-updating-fields/#findComment-567253 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.