alert(window.txtName.value);
This is the wrong way that only works on IE. IE copies all named and IDd elements into properties windowand, therefore, also global variables that cause all kinds of problems. Do not rely on this.
The best way to do it like this:
alert(document.forms[0].elements.txtName.value);
assuming inputbeing in the first <form>on the page. You can also use the form name if it is:
alert(document.forms.someform.elements.txtName.value);
and you can also reduce it:
alert(document.someform.txtName.value);
, .
:
alert(document.getElementsByName('txtName')[0].value);
, id='txt' , , name:
alert(document.getElementById('txt').value);