Return the id of the form containing the <input type="datetime"> element:
var x = document.getElementById("myDatetime").form.id;
Click the button to return the id of the form the datetime field belongs to.
input elements with type="datetime" is supported by Safari.
<!DOCTYPE html> <html> <body> <form id="myForm"> A date control: <input type="datetime" id="myDatetime"> </form>//from ww w .ja v a 2s . c o m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myDatetime").form.id; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The form property returns a reference to the form containing the datetime field.
This property returns a form object on success.
This property is read only.
If the date control is not in a form, null is returned