How to pass checkbox id to the modal box? [duplicate]

纵饮孤独 提交于 2019-12-02 13:33:14

问题


Possible Duplicate:
How to checkbox id to the modal box?

I have a table which each row have a checkbox and a button. whenever the button is pressed, a modal box will appear and at the same time the checkbox will get checked as well.

The modal box will as ask user if want to delete particular record. If Yes, the form will be submitted. If No, the checkbox will be unchecked.

I am facing issue with getting the checkbox unchecked. Anyone can assist with sample code? How do I pass the checkbox id to the modal box so that that particular checkbox can be unchecked?

thank you.

         var buttons3 = $("#yns button").click(function(e) { 
        // get user input
         var yes = buttons3.index(this) === 0;
         if (yes){
         $('form#form1').submit();
         return true;
         } 
        else{
         //How to get the particular Checkbox id so that it can be unchecked? 

$(this).dialog("close");

     return false;

     } 

    });

回答1:


get the id of check box when clicking the button

var id =     $(this).parents('td').siblings()find('.checkbox').attr('id')

uncheck the check box

$('#'+id).attr("checked", false)

with out knowing much details . this may not be the exact answer.........




回答2:


You can find the checkbox by using its common root with the button, then store that object into a variable so that the scope is accessible by the code that reacts to the Cancel operation. I think you could easily use a closure from the Click handler, but here is the code for using the window object as a placeholder.

jQuery > 1.6+

$('#table .button').click(function(){
    //alter this selector to find the checkbox associated with the button.
    window.my_checkbox = $("input[type='checkbox']",$(this).parent()).attr('checked','checked');

    //load modal box...

    if(cancel)
        window.my_checkbox.removeAttr('checked');
});

jQuery < 1.5

$('#table .button').click(function(){
    //alter this selector to find the checkbox associated with the button.
    window.my_checkbox = $("input[type='checkbox']",$(this).parent()).prop('checked',true);

    //load modal box...

    if(cancel)
        window.my_checkbox.prop('checked',false);
});



回答3:


you can assign it to a global variable and access from model dialog cancel event. In onchange event of the checkbox assign the checkbox id to a global variable. And in cancel event of the model dialog you can access it again.

var chk;


$("INPUT[type='checkbox']").click(function(event) {
      chk=  event.target.id;
    });



回答4:


                                    <tr>                                        
                                        <td><input type="checkbox" id="measure<?php echo $count;?>" name="measureid[]" value="<?php echo $items>"></td>
                                        <td><?php  echo $Name;?></td>
                                        <td>
                                            <ul id="tip" class="abuttons">
                                                <li><a class="button"><span class="edit" title="Edit"></span></a></li>
                                                <li><a rel="#yns" id="unitbtn<?php echo $count;?>" class="modalInput button"><span class="delete" title="Delete"></span></a></li>
                                            </ul>
                                        </td>
                                    </tr>


来源:https://stackoverflow.com/questions/6805127/how-to-pass-checkbox-id-to-the-modal-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!