Input Hidden name Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Hidden

Description

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

Set the name property with the following Values

Value Description
name Sets the name of the hidden input field

Return Value

A String, representing the name of the hidden input field

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

A hidden input field:
<input type="hidden" id="myInput" name="country" value="Norway">

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

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

function change() {//  w w w  .  j  av a2 s .com
    var x = document.getElementById("myInput").name = "newName";
    console.log("The name was changed to: " + x);
}
</script>

</body>
</html>

Related Tutorials