Javascript DOM HTML Input DatetimeLocal form Property

Introduction

Return the form's id of containing the <input type="datetime-local"> element:

var x = document.getElementById("myLocalDate").form.id;

Click the button to return the id of the form the local datetime field belongs to.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm">
  <input type="datetime-local" id="myLocalDate">
</form>/*  w w  w.  ja  v a2s  . co  m*/
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myLocalDate").form.id;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The form property returns a reference to the form containing the local 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




PreviousNext

Related