increment jQuery val() not working

I have a function myTimer() which makes a counter. I want to increment input value when user clicks next button and repeat counter. The problem is every time it puts a new value of (rem) in input but I want to increase it by new rem. dur is a variable declared in myTimer() it's user entered to make count, and seconds the variable counted, it's declared in myTimer() too.

  $(document).ready(function(){
       var rem= 0;            
        $("#next").click(function(){
            rem+= dur-seconds-1;
           $("input#time").val(rem);

             myTimer();
       });
});

Answers


You have declared JS variable var rem= 0; inside document.ready.

Declare it globally, before $(document).ready()


Need Your Help

How to add only horizontal padding to a <td> with NO CSS

html-table cellpadding

Is there a way to use cellpadding for just left and right? I am looking for answers but all I keep finding is CSS.

Android - NullPointerException while scrolling in listview with custom adapter

android listview scroll nullpointerexception android-custom-view

I'm trying to emulate a simple chat view using two layouts, one for sent and one for received message. When i try to scroll, a NullPointerException is thrown. Not sure why this happens. Can someone...