Javascript Reference - HTML DOM Input Time name Property








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

The name attribute identifies form data after it has been submitted to the server.

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

Browser Support

name Yes No No Yes Yes

Syntax

Return the name property.

var v = timeObject.name 

Set the name property.

timeObject.name=name




Property Values

Value Description
name Set the name of the time field

Return Value

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

Example

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


<!DOCTYPE html>
<html>
<body>
<!--   w  ww.j a v a2s . c  o m-->
Time: <input type="time" id="myTime" name="usr_time">
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

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

function change() {
    var x = document.getElementById("myTime").name = "newTimeName";
    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 time field.


<!DOCTYPE html>
<html>
<body>
Time: <input type="time" id="myTime" name="usr_time">
<button onclick="myFunction()">test</button>
<!--   www  .j av  a 2  s  .  co  m-->
<p id="demo"></p>

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

</body>
</html>

The code above is rendered as follows: