javascript - How to send 2 select box dynamically generated values via ajax to get 3rd select box values -
i'm trying 3rd select box values according first 2 select box selection (dynamic values);
jquery ajax code (it works airport select box)
$("#airport").change(function() { var aid=$(this).val(); var datastring = 'aid='+ aid; $.ajax ({ type: "post", url: "booking/findcompany.php", data: datastring, cache: false, success: function(data) { $("#company").html(data); } }); }); <select name="site" id="site" class="site"> <option value="" selected="selected">select</option> <option value="1">site one</option> <option value="2">site two</option> <option value="3">site three</option> </select> <select name="airport" id="airport" class="airport"> <option value="1">airport one</option> <option value="2">airport two</option> <option value="3">airport three</option> </select> <select name="company" id="company" class="company"> //options here based on above 2 selected values </select>
php code findcompany.php
<?php if($_post['aid']) { $aid=$_post['aid']; $site=$_post['sid']; <<<<<< how can pass id $compsql=mysql_query("select * tbl_company air_id='$aid' , site_id='$sid'"); while($rows=mysql_fetch_array($compsql)){ $cid=$rows['comp_id']; $cdata=$rows['comp_title']; ?> <option value="<?php echo $cid; ?>"><?php echo $cdata; ?></option> <?php } } ?>
use $('#site').val()
value of 1st select box, , add datastring
. js code -
$("#airport").change(function() { var aid=$(this).val(); var sid=$('#site').val(); var datastring = 'aid='+ aid +'&sid='+sid; ...
Comments
Post a Comment