简体   繁体   中英

jQuery dynamic inserted table rows and input fileds validation on select option

I am trying to build somewhat of a fee voucher with jquery and I am having a heck of a time figuring out how to go about making it all work.

I want when I select option js input field id fee-2 will disable and when I select option php input field id fee-1 will disable and so on more rows inserted for different from select option on different rows. at last need some of all rows inserted by field id fee-1 and fee-2 separately both

图片范例

My Fiddle Demo is

http://fiddle.jshell.net/softfiddle/cSbbK/2/

thanks

$("#mytable").on("change", "select", function () {
     var getSelectValue = $(this).val();
     if (getSelectValue == 1) {
         $(this).parents('td').next().find('#fee-2').prop('disabled', true);
         $(this).parents('td').next().next().find('#fee-1').prop('disabled', false);
     } else {
         $(this).parents('td').next().find('#fee-2').prop('disabled', false);
         $(this).parents('td').next().next().find('#fee-1').prop('disabled', true);
     }
 });

JSFIDDLE

Updated: Have added two classes to the textbox .ie fee_course_1,fee_course_2 so we can loop over it and get sum values

$("#calsum").click(function () {
     var sum_fee_1 = 0;
     var sum_fee_2 = 0;
     $('.fee_course_1').each(function () {
         sum_fee_1 += Number($(this).val());
     });
     $('.fee_course_2').each(function () {
         sum_fee_2 += Number($(this).val());
     });
     alert("Fee_1 = " + sum_fee_1 + "  and  Fee_2 = " + sum_fee_2);

 });

JS FIDDLE DEMO 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM