javascript - jQuery set dropdown value on checkbox change -



javascript - jQuery set dropdown value on checkbox change -

i have grouping of dynamic rows each dropdown , checkboxes , need alter individual dropdown value of row if checkboxes selected.

currently can work if select checkboxes in rows.

how can create row's dropdown changes when checkboxes belongs selected?

i setup fiddle markup of works right now. help!

http://jsfiddle.net/uyv3mk7b/

<!--first row eventregistrations[1]--> <select class="regselect" name="eventregistrations[1].eventregistrationstatustypeid" id="registrationstatusselect"> <option value="1">pending</option> <option value="2">attended</option> </select> <input type="checkbox" class="regchecked" name="eventregistrations[1].markattendance[1].attendancedate" value="1">9/21/14 <input type="checkbox" class="regchecked" name="eventregistrations[1].markattendance[2].attendancedate" value="2">9/22/14 <br> <!--there multiple dynamic rows input names increment eventregistrations[i]--> <!--next dynamic row eventregistrations[2]--> <select class="regselect" name="eventregistrations[2].eventregistrationstatustypeid" id="registrationstatusselect"> <option value="1">pending</option> <option value="2">attended</option> </select> <input type="checkbox" class="regchecked" name="eventregistrations[2].markattendance[1].attendancedate" value="1">10/23/14 <input type="checkbox" class="regchecked" name="eventregistrations[2].markattendance[2].attendancedate" value="2">10/24/14 //change dropdown attended when of checkbox grouping selected //currently works when 4 checkboxes selected, not 2 in each group/row $('.regchecked:checked').length == $('.regchecked').length $(".regchecked").change(function () { if ($('.regchecked:checked').length == $('.regchecked').length) { $('.regselect').val('2'); } });

you need add together wrapper rows, section, or div, , on change, can loop through parents childrens collection.

tyr this: http://jsfiddle.net/uyv3mk7b/3/

html

<!--first row eventregistrations[1]--> <section> <select class="regselect" name="eventregistrations[1].eventregistrationstatustypeid" id="registrationstatusselect1"> <option value="1">pending</option> <option value="2">attended</option> </select> <input type="checkbox" class="regchecked" name="eventregistrations[1].markattendance[1].attendancedate" value="1">9/21/14 <input type="checkbox" class="regchecked" name="eventregistrations[1].markattendance[2].attendancedate" value="2">9/22/14 <br> </section> <!--there multiple dynamic rows input names increment eventregistrations[i]--> <!--next dynamic row eventregistrations[2]--> <section> <select class="regselect" name="eventregistrations[2].eventregistrationstatustypeid" id="registrationstatusselect2"> <option value="1">pending</option> <option value="2">attended</option> </select> <input type="checkbox" class="regchecked" name="eventregistrations[2].markattendance[1].attendancedate" value="1">10/23/14 <input type="checkbox" class="regchecked" name="eventregistrations[2].markattendance[2].attendancedate" value="2">10/24/14 </section>

jquery

//change dropdown attended when of checkbox grouping selected $(".regchecked").change(function() { var checks = $(this).parent().find('.regchecked'); var allchecked = true; $.each(checks, function(idx, value) { if (!$(this).is(':checked')) { allchecked = false; } }); if (allchecked) { $(this).parent().find('.regselect').val(2); } else { $(this).parent().find('.regselect').val(1); } }); //when dropdown value attended, select in checkbox grouping $("select").change(function() { if ($(this).val() === '2') { $(this).parent().find('.regchecked').prop('checked', true); } });

javascript jquery html

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -