
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Input Datetime Type Property
The HTML DOM Input Datetime type property returns/sets type of Input Datetime.
Syntax
Following is the syntax −
- Returning string value
inputDatetimeObject.type
- Setting type to string value
inputDatetimeObject.type = stringValue
String Values
Here, “stringValue” can be the following −
stringValue | Details |
---|---|
date | It defines that input type is date |
datetime | It defines that input type is datetime |
checkbox | It defines that input type is checkbox |
text | It defines that input type is text |
Example
Let us see an example of Input Datetime type property −
<!DOCTYPE html> <html> <head> <title>Input Datetime type</title> </head> <body> <form> <div> Date of Birth: <input type="datetime" id="datetimeSelect" value="2000-09-17T19:22Z"> </div> </form> <button onclick="changeType()">Get Time and Date</button> <div id="divDisplay"></div> <script> var divDisplay = document.getElementById("divDisplay"); var inputDatetime = document.getElementById("datetimeSelect"); divDisplay.textContent = 'Input type: '+ inputDatetime.type; function changeType(){ if(inputDatetime.type === 'text'){ var currDate = inputDatetime.value.split("T")[0]; var currTime = inputDatetime.value.split("T")[1]; } divDisplay.textContent = 'Input Date: '+ currDate+', Input Time: '+currTime; } </script> </body> </html>
Output
This will produce the following output −
Before clicking ‘Get Time and Date’ button −
After clicking ‘Get Time and Date’ button −
Advertisements