jQuery slider going over 100% and issue with disabling empty input -
please see full working code here: http://jsfiddle.net/jfzgn/1/
//enable submit button if (total == 100){ if ($("input:text").is(":empty")) { $("input:text").attr('disabled','disabled'); } else { $("input:text").removeattr('disabled'); } $('.btn').removeattr('disabled'); } else { $('.btn').attr('disabled','disabled'); $("input:text").removeattr('disabled'); }
i having 2 problems jquery:
- when hits 100% disables inputs , want disable empty ones, need able change , if change , goes under 100 other inputs become active again.
- if enter bunch of numbers goes on 100% allows , shows example 120% need stop @ 100%
really helpful if me out here, last task :)
thanks
you'll need test when total greater 100. in example below, set value 0 if total exceed 100, though can put own logic in instead.
if value equal 100, iterate through inputs , disable don't have value.
see updated version of fiddle working example.
if (total == 100){ $("input:text").each(function(index) { var input = $(this); input.prop('disabled', input.val().length === 0); }); $('.btn').prop('disabled', false); } else { if(total > 100) { total = total - thisval; $(this).val(0); alert('total must less 100'); //other logic here } $('.btn').prop('disabled', true); $("input:text").prop('disabled', false); }
as aside, it's recommended use prop()
when working boolean properties disabled, though it's not required.
Comments
Post a Comment