The name property sets or gets the value of the name attribute of a keygen field.
The name attribute specifies the name of the keygen field.
We can also use the name value to reference form-data after it has been submitted or to reference the element in a JavaScript.
The name property is supported in all major browsers, except Internet Explorer.
name |
Yes | No | Yes | Yes | Yes |
Return the name property.
var v = keygenObject.name
Set the name property.
keygenObject.name=name
Value | Description |
---|---|
name | Set the name of the keygen field |
A String type value representing the name of the keygen field.
The following code shows how to change the value of the name attribute of a keygen field.
<!DOCTYPE html>
<html>
<body>
<!-- w w w . j a va 2s . com-->
Encryption: <keygen id="myKeygen" name="security">
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>
<script>
function display() {
var x = document.getElementById("myKeygen").name;
console.log("The name is: " + x);
}
function change() {
var x = document.getElementById("myKeygen").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 keygen field.
<!DOCTYPE html>
<html>
<body>
Encryption: <keygen id="myKeygen" name="security">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--from ww w .j a v a2 s.c om-->
<script>
function myFunction() {
var x = document.getElementById("myKeygen").name;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: