Hi.

Try:
num = 1
SELECT(OPTION('candy',_value=1),OPTION('chocolate',_value=2), value=num)

The SELECT will give selected to the option which has the value of num.

regards
mmlado

On Thursday 22 October 2009 05:26:32 Avik Basu wrote:
> Sorry, my example was too simplistic for what I am trying to achieve.
> Let me try again.
> 
> num = 1
> SELECT(OPTION('candy',_value=1, value=num),OPTION
> ('chocolate',_value=2, value=num))
> 
> the result i want is
> 
> <select>
> <option value="1" selected="selected">candy</option>
> <option value="2">chocolate</option>
> </select>
> 
> this is based on my understanding of the "value" and "_value"
> attributes of the OPTION helper.  here is the relevant text from p.
> 139 of the manual:
> 
> ---
> As in the case of INPUT, web2py make a distinction between "
> value" (the value of the OPTION), and "value" (the current value of
> the enclosing select). If they are equal, the option is "selected".
> ---
> 
> Thanks,
> Avik
> 
> On Oct 21, 10:42 pm, Thadeus Burgess <[email protected]> wrote:
> > No, if you want that option selected pass it a attribute for selected.
> > Anything with an underscore will get passed to the html as an attribute.
> > So you could also go _style="..."
> >
> > OPTION('candy', _selected="selected", _value=1) should produce what you
> > are looking for.
> >
> > However, when using SQLFORM the default selection can be set as well when
> > you specify field.default =...
> >
> > -Thadeus
> >
> > On Wed, Oct 21, 2009 at 9:26 PM, Avik Basu <[email protected]> wrote:
> > > Hello,
> > >
> > > I am a Web2Py newbie trying to use the OPTION helper to create a
> > > dropdown menu that will select the appropriate option.
> > >
> > > I expect that
> > >
> > > OPTION('candy', _value=1, value=1)
> > >
> > > should produce
> > >
> > > <option selected="selected" value="1">candy</option>
> > >
> > > but it only produces
> > >
> > > <option value="1">candy</option>
> > >
> > > Am I doing something wrong? Thanks.
> > >
> > > Avik
> 
> > 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to