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

时间:2014-01-19 06:31:34

标签: javascript php jquery ajax checkbox

请看图像我正在尝试做什么我有每个td里面的HTML表我有下拉和复选框,当我选择下拉值时我想让复选框检查特定的td可以任何人指导我如何做到这一点。

enter image description here

代码:

 <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>

1 个答案:

答案 0 :(得分:2)

要检查下一个td中的复选框,请尝试

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

Jsfiddle