I'm pretty rubbish at picking other people's code apart but this might work better ...
selectID[0].options[i].selected = (selectID[0].options[i].value == valor); break; On Jul 7, 9: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 -~----------~----~----~----~------~----~------~--~---
