The name
property sets or gets the name attribute of a local datetime field.
The name
attribute from input local data time field
identifies form data after it submitting to the server.
We can also use name value reference form data using JavaScript on the client side.
name |
Yes | No | No | Yes | Yes |
Return the name property.
var v = datetimelocalObject.name
Set the name property.
datetimelocalObject.name=name
Value | Description |
---|---|
name | Set the name of the local datetime field |
A String type value representing the name of the local datetime field.
The following code shows how to change the name of a local datetime field.
<!DOCTYPE html>
<html>
<body>
Birthday: <input type="datetime-local" id="myLocalDate" name="bdaytime">
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>
<!--from w w w . j a v a 2 s . c o m-->
<script>
function display() {
var x = document.getElementById("myLocalDate").name;
console.log("The name is: " + x);
}
function change() {
var x = document.getElementById("myLocalDate").name = "newDatetimeName";
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 of a local datetime field.
<!DOCTYPE html>
<html>
<body>
Birthday: <input type="datetime-local" id="myLocalDate" name="bdaytime">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!-- w ww . ja v a 2 s . c o m-->
<script>
function myFunction() {
var x = document.getElementById("myLocalDate").name;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: