Hidden nameProperty

Hidden 对象参考手册Hidden Object

Definition and Usage

The name property can set or return the value of the name attribute of a hidden field.

The name property is used to transmit data to the server after form submission, or to reference form data in JavaScript.

Note:After form submission, only the name attribute of the form element will pass the data value.

Syntax

To set the name attribute:

hiddenObject.name="name"

To return the name attribute:

hiddenObject.name


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the name attribute


Example

Example

The following example returns the name of the hidden input field:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<script>
function displayResult(){
    var x=document.getElementById("hidden1").name;
    alert(x);
}
</script>
</head>
<body>

<form>
<input type="hidden" id="hidden1" name="hidden1">
</form>
<button type="button" onclick="displayResult()">Show the name of the hidden input field</button>

</body>
</html>

Try it Yourself »


Hidden 对象参考手册Hidden Object Other Extensions