Return the id of the form containing the text area:
var x = document.getElementById("myTextarea").form.id;
Click the button to display the id of the form the text area belongs to.
<!DOCTYPE html> <html> <body> <form id="myForm"> <textarea id="myTextarea" rows="4" cols="50"> At java2s.com you will learn how to make a website. </textarea> </form>// www. j av a 2 s .co m <button type="button" onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myTextarea").form.id; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The form property returns a reference to the form that contains the text area.
This property returns a form object on success.
If the text area is not in a form, null is returned