Latest web development tutorials

HTML DOM Input Text value property

Input Text Object Reference Input Text Object

Examples

Modify the values ​​in the text field:

. Document.getElementById ( "myText") value = "Johnny Bravo";

try it"


Definition and Usage

value property sets or returns the value of the property values ​​in the text field.

value attribute contains the value of the default or user input (or via script setting).


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support attribute value.


grammar

Returns the value property:

textObject .value

Set the value property:

textObject .value = text

Property Value

value description
text Track the initial value of the text field

Technical details

return value: String represents the default value of the text field


More examples

Examples

Gets the value of the text field:

var x = document.getElementById ( "myText") value.;

x The output is:

Mickey

try it"

Examples

Forms Authentication:

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 ( "name can not be more than 10 characters");
submitOK = "false";
}
if (isNaN (age) || age <1 || age> 100) {
alert ( "age range 1-100");
submitOK = "false";
}
if (at == - 1) {
alert ( "not legitimate e-mail!");
submitOK = "false";
}
if (submitOK == "false") {
return false;
}

try it"

Examples

Form drop-down list:

var mylist = document.getElementById ( "myList");
document.getElementById ( "favorite") value = mylist.options [mylist.selectedIndex] .text.;

try it"

Examples

Another drop-down list:

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;

try it"


Related Pages

HTML Reference Manual: HTML <the INPUT> value The property


Input Text Object Reference Input Text Object