A html form doesnt need a value element, as the value is obtained from the user input into the form field.
value="" can be used to initialise the field with a null value, or can be used to input a value into a hidden field.
The element
name="" isnt required either if you are using the
getElementById method **
If you use
document.getElementById('txt_Username'); it will return the Username element input by the user eg
var Username = document.getElementById('txt_Username');
You can then do a couple of things to assign a value to the variable
1) Use
Username.value to directly refer to the user input at any point in your code.
2) Assign a permanent new variable
var User_name = Username.value;
OR You could simply cut out all the above steps and directly assign a new variable to the user input by using the following regardless if the value element in the field has been initialised or not:-
var Username = document.getElementById('txt_Username').value;
To put it simply, in this particular case method
document.getElementById('txt_Username').value; means:- give me the user input typed into the text field with element id=txt_Username
The fact that getElementById isnt working in this case is likely due to something else
(See the cookies stuff by asbo)
**
The name field can be accessed using the method
document.forms[0].name, in which case the id field is ignored.
whilst
document.getElementById() concentrates purely on the id field and its input value and ignores the rest.
Either method can be used (name or id).. personally I prefer getElementbyId.