1

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>
1
  • 2
    Please post some code which you have tried so far. So others can point you in right direction Commented Aug 19, 2016 at 11:13

1 Answer 1

1

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);
      });
    });
  });
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @edisoni.1337:)
If you want the numbers to start from 1 in your input types you can add min='1' property but this will change only the min number that user can change not the start value here in javascript code :) Vote up :D
Great ;) Vote up mine too hahah need that ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.