SOS: Select box autochange script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Samuell
    New Member
    • Feb 2008
    • 1

    SOS: Select box autochange script

    Hi, everybody!
    I'm trying to make this script - http://www.w3schools.com/php/php_ajax_database.asp
    roll it's fields from the first to the last automatically
    the code i have at the moment
    Code:
    function roller() {
    var total=3;//number of options
     for (var i=0;i<total;i++) { 
      setTimeout("roll("+i+")", (3000*(i+1)));
     }
     setTimeout("roller()", (3000*total));
    }
    function roll(i) { 
    document.usersform.users[i].fireEvent("onchange")
    }
    do not work an couse an error.
    please, how make this work?
  • wyatt
    New Member
    • Feb 2008
    • 6

    #2
    I believe that running setTimeout ends the current function. Instead, I suggest the following:

    [CODE=javascript]
    function roller(i) {
    var total = 3;
    var i = i : 0;
    roll(i);

    setTimeout("rol ler("+((i+1)%to tal)+")",3000);
    }
    [/CODE]

    Essentially, each time, the function 'roller' is run, a value 'i' is passed to it, which increases by one every time the function runs. However, if it reaches the total, it rolls back to 0 (the '%' modulo operator). If you call roller without passing a value for 'i', it will default to 0.

    Comment

    Working...