JavaScript gets the method of form form id where the button is located

  • 2020-05-26 07:45:44
  • OfStack

The example in this article shows how to get the JavaScript form id where the form button is located. Share with you for your reference. The details are as follows:

The id of the form form button is obtained here using javascript, which can be obtained through the JS code below.


<!DOCTYPE html>
<html>
<body>
<h1>www.sharejs.com</h1>
<form id="form1">
<button id="button1" type="button">Click me!</button>
</form>
<p>The id of the form containing the button is:
<script>
document.write(document.getElementById("button1").form.id);
</script></p>
</body>
</html>

The results are as follows:


The id of the form containing the button is:button1

I hope this article is helpful to you in javascript programming.


Related articles: