I am developing an asp.net application and i want to make it compatible with all 3 major browsers (Internet Explorer, Firefox, Chrome) at least.
In some pages i need to access the form elements through javascript.
What is the correct way to do this so that it works on all browsers?
I have been doing something like this
document.forms[0].elements["nroErros"].value
to access my “nroErros” hidden field for instance and even though this works on IE, it doesn’t seem to work correctly on Firefox.
So, the question is, what is the correct way to make it work always?
It works for me: http://jsfiddle.net/6GJsy/
I believe this is the most cross-browser solution (if you replace
elements[elementName]withelements[elementNumber]).However, as alternatives you could use: