Set different multiple values to different multiple text boxes using Jquery -
i creating script in admin can add charge domestic regions , can add charge international regions. scenario :-
admin clicks add charge button. there can add charge,cost , delivery days. want set value of charge
text boxes having name = delivery_charge[<?php echo $addindex; ?>][charge]
, set value of cost
text boxes having name=delivery_charge[<?php echo $addindex; ?>][cost]
, set value of delivery_days
text boxes having name=delivery_charge[<?php echo $addindex; ?>][days]
.
what i've done is
function addcharges(type){ var cost = parsefloat($('#modal-cost').val()); var charge = parsefloat($('#modal-charge-box').val()); var days = parseint($('#modal-days').val()); if(isnan(cost)){ cost = 0; } if(isnan(charge)){ charge = 0; } if(isnan(days)){ days = 0; } if(type == 'domestic'){ $('.domesticzones :checkbox').prop("checked", true); $('.domesticzones input').prop("readonly", false); //what code should put here text box name delivery_charge[][cost] have value of cost , same variables charge , days. }else if(type == 'international'){ $('.internationalzones :checkbox').prop("checked", true); } }
use :
// find name [cost] @ end of name $('input[name$="[cost]"]').val(cost); // same goes others
the updated comment should trick, , can try solution using regex, need quite new line compared above code :
$('input[name$="[cost]"]').filter(function(){ // find attribute name start `delivery_charge` // name , not followed `_` var regex = /delivery_charge(?!\_)/; if ( regex.test( $(this).attr('name') ) ) return this; }).val(cost);
Comments
Post a Comment