javascript - Plus minus button adjustment using jQuery -


two things:

  1. adjusting plus minus button when reaches min , max range, corresponding button disabled (and apply , remove css - active bold, inactive normal).
  2. output quantity in different div. club diff items.

for example:

i got 3 quantities displayed -

  1. chocolate, vanilla, dark current
  2. chocolate minimum quantity 1, other 2 0 , maximum quantity 6. default 1 chocolate. has there.

but total quantity should not exceed 6. also, in external div, show items - 1 chocolate

now when change chocolate quantity 2, ext div should show (note plural) items - 2 chocolates

now when select dark current (1 q) items - 2 chocolates, 1 dark current

if select vanilla(1 q), div should show items - 4 goodies

that means external "div" displays information of 2 items separately. if more, clubs , generalizes items, shows total quantity.

now if reduce dark current, div should show items - 2 chocolates, 1 vanilla

my issues -

  1. for chocolate, minus button not honoring min quantity, shows zero.
  2. implementing dynamic information in external div (for reason, dark current not increment in fiddle).

link - http://jsfiddle.net/yfgrk/1/

// increment if(defaultinp.val() < jquery(defaultinp).data('max'))      //if put "var _val = " here     //i - [object object] chocolate. why?     $('input[name = ' + fieldname + ']').val(currentval + 1);      //save display in ext div     var _val = currentval + 1;      //show in div     $(".count-pax").text(_val + ' ' + fieldname);     console.log(currentval);      //disable button     if(defaultinp.val() == jquery(defaultinp).data('max'))         $(this).prop('disabled', true);     $(".paxminus").removeattr("disabled"); }  else {     //otherwise put 0 there     $('input[name=' + fieldname + ']').val(0); 

next

// decrement 1 if(defaultinp.val() > minval)      //if put "var _val = " here     //i - [object object] chocolate. why?     $('input[name=' + fieldname + ']').val(currentval - 1);      //save display in ext div     var _val = currentval - 1;      //show in div     $(".count-pax").text(_val + ' ' + fieldname);      //disable button     if(defaultinp.val() == jquery(defaultinp).data('min'))         $(this).prop('disabled', true);     $(".paxplus").removeattr("disabled"); }  else {     //otherwise put 0 there     $('input[name=' + fieldname + ']').val(0); 

to keep things organized, create separate function update total value info. in function, go on <li>'s, appending text our final count on each element has value greater "0".

call function @ end of click events. here example: http://jsfiddle.net/yfgrk/4/

function updatecount() {     var text = "";     $("#myform li").each(function() {         var field = $(this).find("input[field]").attr("field");         var val = $(this).find("input[type=text]").val();         if(parseint(val) > 0) {             text += (text == "" ? "" : ", ") + val + " " + field;         }     });     $(".count-pax").text(text); } 

edit

just explain inline text checking add comma, it's same of doing this:

if(text != "")     text += ", "; text += val + " " + field; 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -