Javascript Reference - HTML DOM Input Submit value Property








The value property sets or gets the value attribute of the submit button.

The value attribute defines the text that is displayed on the submit button.

Browser Support

value Yes Yes Yes Yes Yes

Syntax

Return the value property.

var v = submitObject.value 

Set the value property.

submitObject.value=text




Property Values

Value Description
text The text displayed on the submit button

Return Value

A String type value representing the text displayed on the submit button.

Example

The following code shows how to get the text displayed on a Submit button.


<!DOCTYPE html>
<html>
<body>
<!--   ww w  .j ava2  s. c o  m-->
<input type="submit" id="mySubmit" value="Submit form">
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("mySubmit").value;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to change the text displayed on a Submit button.


<!DOCTYPE html>
<html>
<body>
<input type="submit" id="mySubmit" value="Submit form">
<button onclick="myFunction()">test</button>
<!--   ww  w.ja v a2s. co  m-->
<script>
function myFunction() {
    document.getElementById("mySubmit").value = "newSubmitButtonValue";
}
</script>

</body>
</html>

The code above is rendered as follows: