On 07/08/2010 11:10 AM, P.Canepa wrote:
> Dear All,
> 
> Does anyone know how to select item in listboxes with javascript ? I don't 
> mean to get the value given a selected element in a listbox.
> 
I use the following two javascript functions to set or retrieve the
current menu item by using the item value:

 function idbGetSelected(menu_object) {         /* return value of
selected menu entry */
   for (i=0;i<menu_object.length; ++i) {
     if(menu_object.options[i].selected == true) {
       return menu_object.options[i].value;
     }
   }
   return "";
 }

 function idbSetSelected(menu_object,value) {   /* set selected menu
entry to entry with supplied value */
   if (menu_object) {
     for (i=0;i<menu_object.length; ++i) {
       if(menu_object.options[i].value == value) {
         menu_object.options[i].selected = true;
       } else {
         menu_object.options[i].selected = false;
       }
     }
   }
   return "";
 }

Setting a menu entry would look for example like this:

  idbSetSelected(document.getElementById("color_menu"),"color_custom");

Regards,
Rolf

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to