javascript - Combination of Auto Comma and Auto Sum in jquery -


i have syntax want combine script of having textbox autocomma , auto result whenever input values. there better way this?

          $('.numeric_value').keyup(function() {              var sum = 0;              $('.numeric_value').each(function() {                  sum += number($(this).val());              });              $('#total').val(sum);          });                   $(document).ready(function(){          $("input[data-type='number']").keyup(function(event){            // skip arrow keys            if(event.which >= 37 && event.which <= 40){                event.preventdefault();            }            var $this = $(this);            var num = $this.val().replace(/,/gi, "");            var num2 = num.split(/(?=(?:\d{3})+$)/).join(",");            console.log(num2);            // following line has been simplified. revision history contains original.            $this.val(num2);        });      });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <form class="form-inline">      		<div class="form-group">      			<input type="number" class="numeric_value" autofocus="autofocus">      		</div>      		<div class="form-group">      			<label>+</label>      			<input type="number" class="numeric_value">      		</div>      		<div class="form-group">      			<label>=</label>      			<input type="text" data-type="number" class="form-control" id="total" disabled>      		</div>      	</form>        <!-- <input type="number" class="numeric_value" onkeyup="javascript:this.value=comma(this.value);"> -->         <input class="numeric_value" id="id_step2-number_2" name="step2-number_2" type="text" data-type="number">


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -