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

自作多情 提交于 2019-12-02 04:44:20

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

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);
});

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