user6589814 user6589814 - 3 months ago 17
HTML Question

Add number inside several Input (Type=number) after button click

I have added a button to my application that adds value to

input type='number'
after click. Everything works fine, but numbers starts from 0 and not 1.

How can I make it so after click number starts from 1.

Here is the code and Jsfiddle code: https://jsfiddle.net/gLs374h0/

var arr_example = [1];
$("#btn1").click(function(){
$.each (arr_example, function() {
$( ".order-number" ).each(function(value) {
$( this ).val(value);
});
});
});

<div id="sortable">
<h1 id='btn1'>Sort</h1>
<div class="nested-fields">
<input type="number" placeholder="sort order" class='order-number'>
</div>

<div class="nested-fields">
<input type="number" placeholder="sort order" class='order-number'>
</div>

<div class="nested-fields">
<input type="number" placeholder="sort order" class='order-number'>
</div>

<div class="nested-fields">
<input type="number" placeholder="sort order" class='order-number'>
</div>

<div class="nested-fields">
<input type="number" placeholder="sort order" class='order-number'>
</div>

</div>

Answer

here you have a jsfiddle

 var arr_example = [1];
  $("#btn1").click(function(){
    $.each (arr_example, function() {
      $( ".order-number" ).each(function(value) {
        $( this ).val(value+1);
      });
    });
  });
Comments