form input value through ID, not name

Uttecetbace

New Member
I have a form with an input that has a name an id.When I try to get the value of the input by using \[code\]document.getElementById\[/code\], I get an error.I can access the element by using the form name and the input name, but it makes the script a lot less flexible.Any workarounds?Here's the code I have:\[code\]<form name='myform'> <input name='n1' id='i1' value='http://stackoverflow.com/questions/13870850/stuff'></form><script> var s=document.getElementById("i1").value; alert(s);</script>\[/code\]I have the script in an external .js file and I want to make sure that if someone changes the name of the form, the script still works.
 
Back
Top