Forum Moderators: open

Message Too Old, No Replies

SOS: Form SelectedIndex autochange script

         

Samuell

5:41 pm on Feb 14, 2008 (gmt 0)



Hi,
im actually not an js coder, so i spent a few hours to find script i need but looks like there are no such script
i currently use this stuff -
[w3schools.com ]
so what i need is to make that fields in the box go automatically from first to the last then first again and so on until i choose some field manually.
i tried things like this

function roller() {
for (i=0;i<3;i++) { setTimeout("roll(i)", 3000) }
}
function roll(i) { document.usersform.users[i].selected = "1" }

but it jumps to last field and do not show any of previuos fields. and its do not affect mysql select action so nothing is really happens.
so, is there are any chances to expand that script this way?
thanks in advance

fside

10:54 pm on Feb 14, 2008 (gmt 0)

10+ Year Member



Aren't you setting the timeout on all three for the same instant? Timeout or interval to a function that steps through.

Samuell

11:44 am on Feb 15, 2008 (gmt 0)



ok, one nice guy provide me this upgrade

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].selected = "1";
}

and now its rolls, but its still not affect function inside onchange event of the form, so nothing is happens, its strange couse i thought it should affect
and i have no idea how to stop this rolling

any ideas?

Samuell

8:13 pm on Feb 17, 2008 (gmt 0)



ok, i find out why onchange handler of the form do not react on SelectedIndex change - its just can't be trigered this way, so i'm trying to use
document.usersform.users[i].fireEvent("onchange")

instead of
document.usersform.users[i].selected = "1";

but its still don't work and couse an error, so
what is wrong now and how i can make it work?
please, anybody!

[edited by: Samuell at 8:24 pm (utc) on Feb. 17, 2008]

whoisgregg

2:35 pm on Feb 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe the onchange event is attached to the <select>, not the <option>.

And, you probably need to set .selected = "1" then fire the onchange... Something along these lines:

function roll(i) { 
document.usersform.users[i].selected = "1";
document.usersform.users.onchange();
}