The name
property sets or gets the name attribute of a reset button.
The name
attribute identifies form
data after it has been submitted to the server.
We can also use the name value to reference form data using JavaScript on the client side.
name |
Yes | Yes | Yes | Yes | Yes |
Return the name property.
var v = resetObject.name
Set the name property.
resetObject.name=name
Value | Description |
---|---|
name | Set the name of the reset button |
A String type value representing the name of the reset button.
The following code shows how to change the name attribute of a Reset button.
<!DOCTYPE html>
<html>
<body>
<!--from w w w .ja v a 2s . com-->
<form>
First name: <input type="text" name="fname">
<input type="reset" name="reset1" id="myReset">
</form>
<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 is: " + x);
}
function change() {
var x = document.getElementById("myReset").name = "newName";
console.log("The name was changed to: " + x);
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the name attribute of a Reset button.
<!DOCTYPE html>
<html>
<body>
<!-- www . j av a2 s . c o m-->
First name: <input type="text" name="fname">
<input type="reset" name="reset1" id="myReset">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myReset").name;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: