简体   繁体   English

选中下拉列表时如何选中复选框

[英]how to make the check box checked when drop down is selected

Please see the image what i am trying to do i have HTML table inside the each td i have drop down and check box,when i select value in drop down i want to make the check box checked for the particular td can anyone guide me how to do it. 请看图像我正在尝试做什么我有每个td内的HTML表我有下拉和复选框,当我选择下拉值我想要检查特定td的复选框可以任何人指导我如何去做吧。

在此输入图像描述

code: 码:

 <td style="width:141px" > <select name="mySelect" id="mySelect" class="edit1 route '.$rows["net_id"].'" >         
           <option value="-1">Choose..</option>';


            $query = "SELECT route FROM routestable WHERE `clientid` = '$client_id' "; 

            $result = mysql_query($query);

            while ($rows1 = mysql_fetch_assoc($result))  
            {  


                    if(strlen($rows1['route'])>0 && $rows1['route']==$rows['route']){
    print' <option value="'.$rows1['route'].'" selected>'.$rows1['route'].' </option>';}

                else{

                echo '<option value="' . $rows1['route'] . '"> ' . $rows1['route'] .     '</option>';  

                }

            }   


         echo '</select>
                            </td>


                    <td style="width:200px" id="CPH_GridView1_Status1'.$rows['net_id'].'" class="edit2 status1 '.$rows["net_id"].' "><input type="checkbox" style="margin:0 0 0 93px;" name=""/></td>

ajax 阿贾克斯

<script>

  $(document).ready(function(){

        $('.edit1').on('change', function(){


                                     arr = $(this).attr('class').split( " " );
                                     var clientid=document.getElementById("client").value;
                                     account_id=document.getElementById("account_id").value;


                                        $.ajax({    type: "POST",
                                                    url:"clientnetworkpricelist/routestatusupdate.php",
                                                    data: "value="+$(this).val()+"&rowid="+arr[2]+"&field="+arr[1]+"&clientid="+clientid+"&account_id="+account_id,


                                                    success: function(res){
                                                         data = jQuery.parseJSON(res); //added line
                                                         alert('Saved Successfully!');
                                                         $('#CPH_GridView1_Status'+arr[2]).empty();
                                                         $('#CPH_GridView1_Status'+arr[2]).append(data.status);
                                                         $('.ajax').html($(this).val());
                                                         $('.ajax').removeClass('ajax');
                                                    }});


                                  }  


                         );


     });


</script>

To check the checkbox in the next td try 要检查下一个td中的复选框,请尝试

$(this).parent().next().find('input:checkbox').attr("checked",true);

Jsfiddle 的jsfiddle

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

相关问题 选中时如何将下拉列表的值加载到文本框 - How to load the value of a drop down to a text box when selected 如果复选框处于选中状态,则为下拉列表设置不同的值 - set different values for drop down list if check box checked or unchecked 下拉复选框不起作用 - Drop down with checked box not working 如何使div内容(可能是输入,单选,复选框,数字滑块,下拉菜单等)为只读并在单击按钮时启用? - How to make the div content(it may be input, radio, check box, numeric slider, drop down etc) readonly and enable when click on button? 选择下拉框时要启用的文本框 - Text box to be enabled when drop down box is selected 如何隐藏基于复选框的值,选中时需要包含在内(包括下拉框版本) - How to Hide Value Based On CheckBox include Required when Checked (Drop-down box version included) 如何检查是否在JavaScript中选择了下拉菜单 - How to check if drop-down is selected in JavaScript 如何使用JavaScript检查下拉菜单的选定值是否设置为No且文本框为空 - How to check if the selected value of drop-down is set to No and Text-Box is blank using JavaScript 禁用选择/复选框当另一个被选中/选中时 - Disable the Selection/Check box When the other one is Selected/Checked 在下拉框中选择时不显示选项值 - Option value is not appearing when selected in drop down box
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM