SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how increment the value on each click ??

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

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

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to increment value always by same value:
    first time 0, second 1, 3rd 2.... Do it like this:
    Code:
    //js code
    var i = 0;
    addRow(row)
    {
    alert(i);
    i++;
    }

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    meaning that set your variable i as a global variable and accessible in your function call. but be wary of any modification that might change its value. and you might want to use meaningful name.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •