Search code examples
formsselectparent

Detecting form change get id


I am trying to get the form id when an option in a drop down is selected:

HTML

<form id="test">
     <select id="option1">
      <option id="opt1">Hello</option>
     </select>
 </form>

JS:

$("#test").change(function(){

     var formid=$("test").parent("form");
     alert(formid);

});

The output in the alert is "object object". I have also tried closest which gives the same output.


Solution

  • $("#test").change(function(){
    
         var formid=$("test").parent("form").attr('id');
         alert(formid);
    });