0

I am currenlty using this to see if each rows check box in a specified table is checked.

$("#table_pdf_view input[type=checkbox][checked]").each(

    function() {



    }

 );

If the row is checked I want it to use the checkboxes input id to update a seperate hidden table.

echo '<td width="200px"><input type=" checkbox" id="'.$row['client_id'].'" name="download"></td>'.PHP_EOL;

The hidden table will contain one input field. If multiple rows are checked I would like to separate each id by a comma.

1 Answer 1

3

Do something like

var $checkboxes = $("#table_pdf_view input[type=checkbox]");
$checkboxes.on('change',function(){
   var ids = $checkboxes.filter(':checked').map(function(){
      return this.id; 
   }).get().join(',');
   $('#Hidden_input_id').val(ids);
});

Change #Hidden_input_id with the ID of your hidden input. This will update hidden input's value when users check/uncheck a checkbox.

Demo: http://jsfiddle.net/npmB3/1/

Read more on .on() and .map()

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, works perfectly until you specify the boundary for the checkboxes jsfiddle.net/npmB3/8
@SamCorbet, thats because your markup is not valid and browser's correct the markup, like chrome takes the checkboxes out of table and the selector returns empty set. You have to put the checkboxes inside td. Like this jsfiddle.net/npmB3/13
Thank you, for some reason I cant get it to work on my actual page but I'm sure it wont be too hard to figure out why. many thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.