[RESOLVED]how can I augment a value by 1 each time a button is clicked

I am new to Jquery but am having trouble trying to augment the value of a textbox when a button is clicked

       <script>
                   $(document).ready(function () {
                       
  $("#moreresults").click(function () {
                           var page = $("#page").val();
                           page = page++;
                           alert(page);
                       });
</script>
 <input type="hidden" id="page" name="page" value="1" />
        <input type="submit" id="moreresults"  value="More" />

As you can see the textbox starts with a default value of 1, each time I click the button the answer is always 1 and the default value does not increase. Any suggestions would be great …

First of all, you are not saving the incremented value back to hidden field and when you increment, you need to get integer value and then increment. So modified code will be like following.

$("#moreresults").click(function () {
                           var page = $("#page").val();
                           page = parseInt(page) + 1;
                           alert(page);
                           $("#page").val(page);
                       });

Thanks alot that worked

Leave a Reply