Input Text value Property
The value property sets or returns the value of the value attribute of a text field.
The value property contains the default value OR the value a user types in (or a value set by a script).
Browser Support
Syntax
Return the value property:
Property Values
Technical Details
More Examples
Example
Get the value of a text field:
Example
var at = document.getElementById(«email»).value.indexOf(«@»);
var age = document.getElementById(«age»).value;
var fname = document.getElementById(«fname»).value;
submitOK = «true»;
if (fname.length > 10) alert(«The name may have no more than 10 characters»);
submitOK = «false»;
>
if (isNaN(age) || age < 1 || age >100) alert(«The age must be a number between 1 and 100»);
submitOK = «false»;
>
if (at == -1) alert(«Not a valid e-mail!»);
submitOK = «false»;
>
if (submitOK == «false») return false;
>
Example
var mylist = document.getElementById(«myList»);
document.getElementById(«favorite»).value = mylist.options[mylist.selectedIndex].text;
Example
var no = document.getElementById(«no»);
var option = no.options[no.selectedIndex].text;
var txt = document.getElementById(«result»).value;
txt = txt + option;
document.getElementById(«result»).value = txt;
Example
An example that shows the difference between the defaultValue and value property: