Javascript Reference - HTML DOM Input Datetime name Property








The name property sets or gets the name attribute of a datetime field.

The name attribute from input datetime field identifies form data after submitting to the server.

We can also use name value to reference form data using JavaScript on the client side.

Browser Support

name No No No No No

Syntax

Return the name property.

var v = datetimeObject.name

Set the name property.

datetimeObject.name=name




Property Values

Value Description
name Set the name of the datetime field

Return Value

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

Example

The following code shows how to change the name of a datetime field.


<!DOCTYPE html>
<html>
<body>
<!--   w  ww . j av  a 2 s.  c  o m-->
Birthday: <input type="datetime" id="myDatetime" name="bdaytime">
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

<script>
function display() {
    var x = document.getElementById("myDatetime").name;
    console.log("The name is: " + x);
}

function change() {
    var x = document.getElementById("myDatetime").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 datetime field.


<!DOCTYPE html>
<html>
<body>
<!--from  w  w w  . j av  a2 s. c o  m-->
Birthday: <input type="datetime" id="myDatetime" name="bdaytime">
<button onclick="myFunction()">test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myDatetime").name;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: