How to get the id of a form containing a dropdown list with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

To get the id of a form with a drop-down list, use the id property in JavaScript.


You can try to run the following code to find the id of a form containing drop-down list −

Live Demo

<!DOCTYPE html>
      <form id="myForm1">
         <button id="btn" type="button" value="my_button">Demo</button>
      <form id="myForm2">
         <select id="mySelect">
         var val = document.getElementById("mySelect");
         document.write("<br>Form id with dropdown: "+val);
Updated on 23-Jun-2020 08:46:03