Input Button valueProperty
Button Object
Definition and Usage
The value property sets or returns the value of the value attribute of the button element.
The value attribute specifies the text displayed on the button.
Syntax
Setting the value property:
buttonObject.value="value"
Returning the value property:
buttonObject.value
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the value property
Example
Example
Display the text of the button:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("button1").value;
alert(x);
}
</script>
</head>
<body>
<form>
<input type="button" onclick="displayResult()" id="button1" value="Display button text">
</form>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("button1").value;
alert(x);
}
</script>
</head>
<body>
<form>
<input type="button" onclick="displayResult()" id="button1" value="Display button text">
</form>
</body>
</html>
Try it Yourself »
Button Object Other Extensions