views:

29

answers:

1
<table> 
  <tr>
   <td>
    <div>
     <input type="checkbox" id="home1">Home1</input>
     <input type="checkbox" id="home2">Home3</input>
     <input type="checkbox" id="home3">Home3</input>
     <input type="checkbox" id="home4">Home4</input>
   </div>
  </td>
  <td id="selectedhome"> </td>
 </tr>
</table>

<input type="button" value="Select" />

In the above code onclick of the button all the selected values of the check box should appear in the selectedhome td with a undo link next to to it and be invisible from the first td.Onselect the undo button the checkbox should go back to the initial position.How to achieve this using jquery

+2  A: 

Give this a try. It will reset each checkbox to the default checked value it had when the page loaded.

Example: http://jsfiddle.net/6kFMk/1/

  // Display ID value of checked boxes
$('input[value=Select]').click(function() {
    var values = $('table :checkbox:checked').map(function() {
        return this.id;
    }).get().join(',');
    var home = $('#selectedhome').text(values);
});

  // Reset checkboxes to initial state
$('input[value=Undo]').click(function() {
    $('table :checkbox').each(function() {
        this.checked = this.defaultChecked;
    });
});​
patrick dw
@patrick:I wanted to get the checkboxes that are selected in the second td.And on undo put back the same to the original position in the first td
Hulk
@Hulk - Are you saying that you saying that when someone checks a checkbox, the entire checkbox should move into the second `<td>`?
patrick dw
@patrick: yes that was intended
Hulk