Reseting a select box

0 views
Skip to first unread message

a.re...@gmail.com

unread,
Nov 16, 2007, 1:16:38 PM11/16/07
to rubyonrail...@googlegroups.com
Hello,

is there a way to reset a select box to it's default value?

Or do I habe to use update() on the select box to empty it and then add all the options again?

TIA,
Alex

Bastian Feder

unread,
Nov 16, 2007, 2:41:34 PM11/16/07
to rubyonrail...@googlegroups.com
Hi,
actually you just need to find out which is the default value of your
select box and then select this via script.
I use the following code for it:

<--snip-->

for (var i=0;i<sel.options.length;i++) {
sel.options[i].selected = sel.options[i].defaultSelected;
}

<--snip-->

Add this to you "resetMySelectBox(sel)"- function and you'll be happy ;o)

hf
Bastian

--
--
spread the word ... see www.browsehappy.com ;o)

Calvin: Weekends don't count unless you spend them doing something
completely pointless.

Join the Greater IBM Connection (http://www.xing.com/premiumgroup-6291.d26b7d)

a.re...@gmail.com

unread,
Nov 16, 2007, 8:13:11 PM11/16/07
to rubyonrail...@googlegroups.com
Bastian,

DOH! Sometimes I should recall the orginal javascript possibilities.

As I have several select boxes and the first option is always the default option I
used the following solution:

$$('fieldset#ep4hd select').each(function(s){ s.selectedIndex = 0;})

Anyway thanks again.

Alex

2007/11/16, Bastian Feder <bastia...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages