how increment the value on each click ??

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

how increment the value on each click ??

Post by PHPycho »

Hello forums !!
How to increment the value on each function call ?
Suppose i had a function called
addRow()

Code: Select all

//js code
addRow(row)
{
var i = 0;
alert(i);
}
suppose this function is called with onclick event of button.
when clicked first time it should alert 0, 2nd time => 2 3rd time => 3..
I hope you got my question, awaiting for your valueable help.
Thanks in advance to all of you
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. Declare the variable outside of the function
  2. increment the variable inside the function
Post Reply