views:

25

answers:

2

In the below code how to get the checkboxes that are selected only and remove it from the list using jquery and populate the removed html in the div

     <div id="section_val">
     <input type="checkbox" name="a_d" value="1">a_d</input>
     <input type="checkbox" name="a_d" value="2">a_d1</input>
     <input type="checkbox" name="a_d" value="3">a_d2</input>
     <input type="checkbox" name="a_d" value="4">a_d3</input>
     </div>

     <div id="populate"></div>

   <input type="button" value="Select" onclick="get_Selected();"/>
   <input type="button" value="Retain" onclick="=retain;"/>

   <script>
   function get_Selected()
   {

   }

    function retain()
    {

     }
    </script>
+1  A: 
<input type="checkbox" name="a_d" value="1" /><label>a_d</label>
<input type="checkbox" name="a_d" value="2" /><label>a_d1</label>
<input type="checkbox" name="a_d" value="3" /><label>a_d2</label>
<input type="checkbox" name="a_d" value="4" /><label>a_d3</label>

<div id="populate"></div>

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

<script>
$(function() {
    $('#getSelected').click(function() {
        $('[name="a_d"]:checked').each(function(){
            $(this).next().andSelf().appendTo('#populate');
        });
    });
});​
</script>

demo

Reigel
And if there is a retain button how to retain it back..
Rajeev
are those checkboxes inside a wrapper div or whatsoever wrapper?
Reigel
please check [update1](http://jsfiddle.net/Pxy4p/1/)
Reigel
@Reigel :yes those checkboxes are inside a div.Please see the edit in the question for the div
Rajeev
please check [update1](http://jsfiddle.net/Pxy4p/1/)
Reigel
@Reigel:Thankss
Rajeev
you are welcome ;)
Reigel
A: 
function get_Selected()
   {

     //collect select
     var _selectedCheckBoxes=jQuery('input[type=checkbox]').filter(':checked');

     // fill dom
     var _text="";  
    _selectedCheckBoxes.each(function(){
      _text+='<br>'+jQuery(this).value();
    });
    jQuery('#populate').html(_text)

    // clear check boxes
    _selectedCheckBoxes.remove()

   }
Praveen Prasad
And if there a retain button.How to retain it back...
Rajeev