HTML DOM Input DatetimeLocal type Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Input DatetimeLocal type property returns/sets type of Input DatetimeLocal.

Syntax

Following is the syntax −

  • Returning string value
inputDatetimeLocalObject.type
  • Setting type to string value
inputDatetimeLocalObject.type = stringValue

String Values

Here, “stringValue” can be the following −

stringValueDetails
dateIt defines that input type is date
datetime-localIt defines that input type is datetime-local
checkboxIt defines that input type is checkbox
textIt defines that input type is text

Example

Let us see an example of Input DatetimeLocal type property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input DatetimeLocal type</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>Datetime-Local-type</legend>
<label for="datetimeLocalSelect">Inauguration Date-Time :
<input type="datetime-local" id="datetimeLocalSelect" value="2020-01-01T10:00">
</label>
<input type="button" onclick="getEvent()" value="Where is the event? ">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputDatetimeLocal = document.getElementById("datetimeLocalSelect");
   function getEvent() {
      if(inputDatetimeLocal.type === 'datetime-local')
         divDisplay.textContent = 'Event Inauguration near you';
      else
         divDisplay.textContent = 'Event Inauguration in India';
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Where is the event?’ button −

After clicking ‘Where is the event?’ button −

raja
Published on 24-Jul-2019 14:21:36
Advertisements