Re: "Undefined" in scrolling_list
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: "Undefined" in scrolling_list

From: RobG <rgqld@iinet.net.au>
Date: Mon Jan 23 2006 - 02:00:10 CET

William wrote:
> I tried to update a scrolling_list with the following:
>
> function saveText( scroll_list, t_area, listToBeUpdated ) {
> var updated = new Option();
> updated.value = t_area.value;
> updated.text = t_area.text;

Why create a new option when you just want to modify the attributes of
the one that is there?

      var o = scrollList.options[scroll_list.selectedIndex];
      o.value = t_area.value;
      o.text = t_area.text;
   }

Anyhow, if you wanted to create a new option, use:

      var updated = new Option(t_area.text, t_area.value, false, true);

(false sets the option's defaultSelected property to false, true sets
the option to selected).

> scroll_list.options[scroll_list.selectedIndex] = updated;
> }
>
> but I get "Undefined" in the position with the new Option() (i.e.
> "updated").

Because IE doesn't let you modify the properties of new options
directly, so either modify an existing option or use new Option() to set
the values when the option is created.

-- 
Rob
Received on Tue Feb 7 21:18:36 2006