PDA

View Full Version : how increment the value on each click ??



PHPycho
Apr 18th, 2007, 06:21 AM
Hello forums !!
How to increment the value on each function call ?
Suppose i had a function called
addRow()


//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

david_kw
Apr 18th, 2007, 06:41 AM
Try this.


//js code
var i = 0; // take it outside the function to make it global
addRow(row)
{
alert(i++); // increment it after showing the current value
}

david_kw