简体   繁体   中英

how to get id of each selected item from two different drop down list using ajax

how to get id of selected item from two different drop down list. after comparing them if they were same then how to fetch a record from database without reloading a page using ajax and php.

<select name="bgnm" id="bg" class="demoInputBox" onChange="getState(this.value);">  <?php
     $dd_res=mysql_query("Select * from building");
     while($r=mysql_fetch_row($dd_res))
     { 
           echo "<option value='$r[0]'> $r[1] </option>";
     }

 ?> </select> 




 <select name="flat number" id="flat" onChange="getflat(this.value);"> <?php
     $dd_ress=mysql_query("Select * from building");
     while($r=mysql_fetch_row($dd_ress))
     { 
           echo "<option value='$r[2]'> $r[2] </option>";
     }
 ?>

You can call getValue() function (as described below) whenever a value changes in any of the dropdown.

function getValue() {
var val1=$('bg').val();
var val2=$('flat').val();
if(val1==val2)
{            
     $.ajax({
            url: '{{ url("activeDomain") }}',
            type: 'get',
            //async:true,
            data: {
                id: val1
            },
            dataType: 'json',
            success: function(json) {

              //do whatever you wanted to do
            //you can easily manipulate DOM using jQuery
  },
            error : function(xhr, textStatus, errorThrown ) {
                //in case ajax call error
            }
        });
    }
  }
else{
  //you can send another ajax call
  //use code as above
 }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM