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

2019-02-26 02:27发布

问题:

Possible Duplicate:
How to pass 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;

 } 

});

My Modal Box Html:

<div class="widget modal2" id="yns"> <header>
 <h2>Confirmation</h2></header> <section>
   <p> Do you want to delete this item? </p> <!-- yes/no buttons --> <p> 
<button class="button" type="button">Yes</button> 
<button class="button" type="button">No</button> 
</p> </section> </div> 

My Table HTML:

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

Modal and Table within same php page.

回答1:

May-be an easy way to do that is to uncheck every checkboxes in your table if the user clicks on No.



回答2:

your question not clear to me, so i have assumed (not a very good one) that only one checkbox is checked at a moment so you can uncheck it by

$("input[name='measureid\\[\\]']:checked").removeAttr("checked")

it will uncheck the checkbox that is checked and has name="measureid[]"