[thelist] Stupid JS trick

Hershel Robinson hershelsr at yahoo.com
Thu Aug 9 04:44:55 CDT 2001


> I need the select elements to show dynamic values based on the selections
of
> the other select elements, using JavaScript to avoid a refresh.

I am not a guru in these matters, but I believe that to remove an element of
an HTML select box requires a refresh, even if you remove the element via
JavaScript.  This what the NetScape JavaScript Reference says:

After you delete an option, you must refresh the document by using
history.go(0). This statement must be last. When the document reloads,
variables are lost if not saved in cookies or form element values.

You thus have (at least) 2 choices.  Either you can initially create the
cities select box with enough options to accommodate even the largest state
and then just change all the values of the options when the user selects a
state.  If the new state has fewer cities than the largest state, just make
the remaining options the null string "" or you may need a single space " ".
If the user then selects one of those, just ask him not to.

The other, perhaps smarter (certainly better-looking) option, is to
initially create a separate select box for each state and then using some
very simple DHTML, just show and hide the select boxes as appropriate when
the user selects a state.

Hope this helps,
Hershel


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com





More information about the thelist mailing list