Javascript DOM HTML Input Time defaultValue Property set

Introduction

Change the default value of a time field:

document.getElementById("myTime").defaultValue = "18:00";

Click the button to change the default value of the time field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Time: <input type="time" id="myTime" value="21:43:54">
<button type="button" onclick="myFunction()">Test</button>

<script>
function myFunction() {//from  ww  w .j  a  va 2 s.co m
  document.getElementById("myTime").defaultValue = "18:00";
}
</script>

</body>
</html>

The defaultValue property sets or gets the default value of a time field.

The default value is the value specified in the HTML value attribute.

The defaultValue contains the default value, while value contains the current value.

If there are no changes, defaultValue and value is the same.

The <input type="time"> element is not supported in Firefox.

The defaultValue property accepts and returns a String type value.

Value Description
value Specifies the default value of the search field

The defaultValue property returns a String representing the default value of the search field.




PreviousNext

Related