[thelist] One more Javascript question

.jeff jeff at members.evolt.org
Thu Dec 12 12:42:01 CST 2002

josh & ppk,

> From: Peter-Paul Koch
> > Is there any way to revert a option value changed by
> > Javascript back to the default (what you would see if
> > you view the source of the page)?
> You might try the defaultValue property, but I'm not
> sure if it works for options.

up til very recently i thought this too.  however, upon checking i found
that the select object does not have a defaultValue property.  try alerting
it and see for yourself.  i'm guessing this is because a select object can
be set to multiple making the defaultValue insufficient in storing the
default selected options.

notice the key words in that last sentence -- default selected options.  in
order to reset a select object, one must walk the select list checking the
defaultSelected property of each option.  any that are true were selected by
default.  if the select object doesn't have the multiple property then you
can save some processing by breaking out of the loop once you find the first
option that's defaultSelected.


jeff at members.evolt.org

More information about the thelist mailing list