You could use many of the enumerable methods, this seems a bit verbose but gets the job done.
Enumerable.find will iterate over the collection until the iteration function returns a value of true. I could have used each, but potentially would have iterated more than necessary, as we'd really want to halt search after a successful find. http://prototypejs.org/api/enumerable/find $A(select.options).find(function(option, index){ if(option.value == someValue){ select.selectedIndex = index; return true; } return false; }); -- http://positionabsolute.net On Jul 7, 4:58 pm, Martín Marqués <[email protected]> wrote: > I'm trying to select an option from a select, but by value, and not by > index. I'm trying like this: > > function selectOptionByValue(selectID,valor){ > > var found = false; > var i = 0; > > while(!found && i<selectID[0].options.length){ > if(selectID[0].options[i].value == valor) { > selectID[0].options[i].selected=true; > found = true; > } > i++; > } > > } > > I would call this function passing as argument the DOM object of the > select and the option value that should be selected. > > Is there an easier way of doing this? > > BTW, it's not working for me. > > -- > Martín Marqués > select 'martin.marques' || '@' || 'gmail.com' > DBA, Programador, Administrador --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
