简体   繁体   English

如何通过Ajax发送2个选择框动态生成的值以获取第3个选择框值

[英]How to send 2 select box dynamically generated values via ajax to get 3rd select box values

I'm trying to get 3rd select box values according to first 2 select box selection (dynamic values); 我试图根据前两个选择框选择(动态值)获得第三个选择框值;

jQuery ajax code is (It only works with airport select box) jQuery ajax代码是(仅适用于机场选择框)

$("#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 is findcompany.php PHP代码是findcompany.php

<?php
if($_POST['aid']) {
    $aid=$_POST['aid'];
    $site=$_POST['sid']; <<<<<< How Can I pass This ID
    $compsql=mysql_query("select * from tbl_company Where air_id='$aid' and 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() to get the value of the 1st select box, and then add it to your dataString . 使用$('#site').val()获取第一个选择框的值,然后将其添加到dataString So now your js code would look like - 所以现在您的js代码看起来像-

$("#airport").change(function()
    {
    var aid=$(this).val();
    var sid=$('#site').val();
    var dataString = 'aid='+ aid +'&sid='+sid;
    ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Ajax和PHP发送多选框值 - Send Multi Select box Values with Ajax & PHP 如何获取动态生成的复选框值 - How to get dynamically generated check box values 如何使用for循环从选择选项框中获取值[选择选项框是动态创建的] - how to get values from select option box using for loop [select option box is created dynamically] 在键盘上添加2个输入值以在第3个输入框中获得答案 - Adding 2 input values on keyup to get the answer in the 3rd input box 如何将选择复选框的值动态传递给ajax调用变量,然后动态传递给php变量 - How to pass the select check box values dynamically to the ajax call variables post to php variables dynamically 更改选择框的值会更改在angularjs中动态生成的其他选择框的值 - Changing the value of select box changes the values of other select boxes which are dynamically generated in angularjs 通过Ajax调用分配值以选择框 - Assign values to select box through Ajax call 如何在Multiselect组合框中动态选择值-LovCombo ExtJS 3.2 - How to dynamically select values in Multiselect combo box - LovCombo ExtJS 3.2 如何基于文本框的值动态更改选择框的值 - how to dynamically change the values of select box based on the value of textbox dojo 过滤选择与 ajax 调用 - 如何使用返回值填充 select 框 - dojo filteringselect with ajax call - how to populate select box with returned values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM