Input Number name Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Number

Description

The name property sets or gets the name attribute of a number field.

Set the name property with the following Values

Value Description
name Sets the name of the number field

Return Value

A String, representing the name of the number field

The following code shows how to get the name of a number field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="number" id="myNumber" name="quantity">

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

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

function change() {//  w  ww  . j  a  v  a  2 s.  co m
    var x = document.getElementById("myNumber").name = "newNumberName";
    console.log("The name was changed to: " + x);
}
</script>

</body>
</html>

Related Tutorials