The name attribute from input color element identifies form data after submission.
We can also use the name value to reference form data using JavaScript on the client side.
The name
property sets or gets the name attribute of a color picker.
name |
Yes | No | Yes | No | Yes |
Return the name property.
var v = colorObject.name
Set the name property.
colorObject.name=name
name | Description |
---|---|
name | Set the name of the color picker |
A String type value representing the name of the color picker.
The following code shows how to change the name of a color picker.
<!DOCTYPE html>
<html>
<body>
A color picker: <input type="color" id="myColor" name="favcolor">
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>
<script>
function display() {
var x = document.getElementById("myColor").name;
console.log("The name is: " + x);
}<!--from www .j a v a2s . co m-->
function change() {
var x = document.getElementById("myColor").name = "newColorName";
console.log("The name was changed to: " + x);
}
</script>
</body>
</html>
The code above is rendered as follows: