Javascript Reference - HTML DOM Input DatetimeLocal name Property








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.

Browser Support

name Yes No No Yes Yes

Syntax

Return the name property.

var v = datetimelocalObject.name

Set the name property.

datetimelocalObject.name=name




Property Values

Value Description
name Set the name of the local datetime field

Return Value

A String type value representing the name of the local datetime field.

Example

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:





Example 2

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: