HTML DOM Input Time defaultValue Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Input Time defaultValue property sets/returns the default value corresponding to Time Input. The value attribute changes as the user changes the time but default value does not change.

Syntax

Following is the syntax −

  • Returning string value
inputTimeObject.defaultValue
  • Setting defaultValue to string
inputTimeObject.defaultValue = ‘string’

Example

Let us see an example of Input Time defaultValue property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input Time defaultValue</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form>
<fieldset>
<legend>Time-defaultValue</legend>
<label for="TimeSelect">Meeting At:
<input type="time" id="TimeSelect" value="09:30">
</label><br>
<input type="button" onclick="changeMeet('Alternate')" value="Alternate Meeting Time">
<input type="button" onclick="changeMeet('Default')" value="Default Meeting Time"><br>
<input type="button" onclick="confirmMeet()" value="Confirm Meeting">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputTime = document.getElementById("TimeSelect");
   function changeMeet(string) {
      if (inputTime.disabled === false) {
         if(string === 'Alternate')
            inputTime.value = '10:30';
         else
            inputTime.value = inputTime.defaultValue;
      }
   }
   function confirmMeet() {
      inputTime.disabled = true;
      divDisplay.textContent = 'Meeting fixed at : '+inputTime.value;
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Alternate Meeting Time’ button −

Changing Time Input by clicking ‘Alternate Meeting Time’ button −

After clicking ‘Default Meeting Time’ button −

After clicking ‘Confirm Meeting’ button −

raja
Updated on 30-Jul-2019 22:30:26

Advertisements