HTML DOM Input Time name Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Input Time name property returns a string, which displays the value of the name attribute of input Time. User can also set it to a new string.

Syntax

Following is the syntax −

  • Returning string value
inputTimeObject.name
  • Setting name attribute to a string value
inputTimeObject.name = ‘String’

Example

Let us see an example of Input Time name property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input Time name</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-name</legend>
<label for="TimeSelect">Appointment at Stephan:</label>
<input type="time" name="Stephan" id="TimeSelect" value="18:00">

<input type="button" onclick="changeMeeting()" value="Confirm">
<input type="button" onclick="changeName()" value="Book at Dorcel's">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var labelDisplay = document.getElementsByTagName("label")[0];
   var divDisplay = document.getElementById("divDisplay");
   var inputTime = document.getElementById("TimeSelect");
   function changeMeeting() {
      if(inputTime.name === 'Stephan')
            divDisplay.textContent = 'Stephan Hospital is closed today';
      else
         divDisplay.textContent = 'Appointment at Dorcel Hospital fixed at: '+inputTime.value;
   }
   function changeName(){
      inputTime.name = 'Dorcel';
      labelDisplay.textContent = 'Appointment at '+inputTime.name+': ';
   }
</script>
</body>
</html>

Output

This will produce the following output −

After clicking ‘Confirm’ button −

After clicking ‘Book at Dorcel’s’ button −

After clicking ‘Confirm’ button with name attribute set to another name −

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

Advertisements