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? Quote 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> Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/110491-solved-updating-fields/#findComment-567253 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.