Input Reset name Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Reset

Description

The name property sets or gets the name attribute of a reset button.

Set the name property with the following Values

Value Description
name Sets the name of the reset button

Return Value

A String, representing the name of the reset button

The following code shows how to get the value of the name attribute of a Reset button:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form>
First name: <input type="text" name="fname">
<input type="reset" name="reset1" id="myReset">
</form>//from  w  w  w.  j a  v  a2s . co m

<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

<script>
function display() {
    var x = document.getElementById("myReset").name;
    console.log("The name of the Reset button is: " + x);
}

function change() {
    var x = document.getElementById("myReset").name = "newName";
    console.log("The name was changed to: " + x);
}
</script>

</body>
</html>

Related Tutorials