The form
property gets the form containing the number field.
form |
Yes | Yes | Yes | Yes | Yes |
var v = numberObject.form
A reference to the form element containing the number field. If the number field is not in a form, null is returned.
The following code shows how to get the id of the form containing the <input type="number"> element.
<!DOCTYPE html>
<html>
<body>
<!-- w ww . j a v a2s. co m-->
<form id="myForm">
<input type="number" id="myNumber" value="2">
</form>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myNumber").form.id;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: