Javascript Reference - HTML DOM Input Datetime form Property








The read only form property returns a reference to the form containing the datetime field.

Browser Support

form No No No No No

Syntax

var v = datetimeObject.form

Return Value

A reference to the form element containing the datetime field. If the date control is not in a form, null is returned.





Example

The following code shows how to get the id of the form containing the <input type="datetime"> element.


<!DOCTYPE html>
<html>
<body>
<form id="myForm">
A date control: <input type="datetime" id="myDatetime">
</form><!--from   ww w.j a v a  2 s  .com-->
<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 code above is rendered as follows: