Input Submit form Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Submit

Description

The form property returns the form that contains the submit button.

This property is read only.

Return Value

A reference to the form element containing the submit button. If the submit button is not in a form, null is returned

The following code shows how to return the id of the form containing the <input type="submit"> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form action="#" method="get">
  First name: <input type="text" name="fname" value="Mary"><br>
  Last name: <input type="text" name="lname" value="Bond"><br>
  <input type="submit" id="mySubmit" value="Submit" formtarget="_blank">
</form>/*from  w  ww  . j a v a  2s.c  om*/

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("mySubmit").formTarget = "_self";
    document.getElementById("demo").innerHTML = "The value of the formtarget attribute was changed from '_blank' to '_self'.";
}
</script>

</body>
</html>

Related Tutorials