jquery - javascript checkbox check all -


i'm working on check button, i'm bit unfamiliar javascript part.

essentially, have checkbox @ top of page, , when check it, goes through , changes checkbox in each row of table checked.

i've looked around @ similar questions , know have use

~~~~.prop('checked', ...) 

this checkbox have check boxes in table.

    <div class="disc-opt" style="float:left">         adjust                     <div class="make-switch">             <input type="checkbox" class="create-adjustments"  />         </div>     </div> 

this table row layout.

<tr class="<?= $data['adjusted'] ? "success" : "" ?>">     <td>        stuff     </td>     <td><?= $data['products_name'] ?></td>     <td><?= $data['total_final_quantity'] ?></td>     <td><?= $data['total_onhand'] ?></td>     <td><?= $data['difference'] ?> </td>     <td><?= $data['difference_cost'] ?></td>     <!-- checkbox changed -->     <td class = "adjustbox">         <?php if(!$data['adjusted']): ?>             <div class="make-switch">                 <input type="checkbox" name="adjust_products[]"                                     value="<?= $products_id ?>">             </div>         <?php else: ?>             adjustment complete         <?php endif; ?>     </td> </tr> 

edit: here's i'm working with(i'm not sure if poorly set up, it's bunch of old code i've never touched before today). i've made edits in code above well.

function createadjustments() {     if($("#create-adjustments").is(':checked'))     {         //turn on     } else {         //turn off     } }  $('#create-adjustments').change(function(e) {     createadjustments(); });  $('#create-adjustments').trigger('change'); 

i've been able access element in table row via document.ready function, couldn't work when checked checkbox.

here's picture of i'm trying do:checkbox on top left 1 want check check in table.

i'm trying make when check checkbox on top left, goes through table , checks of checkboxes in right column.

take @ this did similar thing earlier , did trick me. pretty much, create div input boxes , mark of them checked if main 1 clicked.

html:

<label><input type="checkbox" name="sample" class="selectall"/> select all</label>  <div id="checkboxlist">      <label><input type="checkbox" name="sample[]"/>checkbox1</label><br />     <label><input type="checkbox" name="sample[]"/>checkbox2</label><br />     <label><input type="checkbox" name="sample[]"/>checkbox3</label><br />     <label><input type="checkbox" name="sample[]"/>checkbox4</label><br />  </div> 

javascript:

$('.selectall').click(function() {     if ($(this).is(':checked')) {         $('div input').attr('checked', true);     } else {         $('div input').attr('checked', false);     } }); 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -