I'm not sure why it's always on but you can store the state of the
checkbox in a hidden field and pass it back with the ajax request like
so:

def search2():
    form = FORM(
                TABLE(
                    TR(INPUT(_name='mytxt', _id='mytxt', _value='a
text...')),
                    TR(INPUT(_type='checkbox', _name='mychk',
_id='mychk',_checked="true",_onclick="jQuery('#chkval').val
(this.checked)")),
                    TR(INPUT
(_type='hidden',_name='chkval',_id='chkval')),
                    TR(INPUT(_type="button", _value="Buscar",
                             _onclick="ajax('%s',['mytxt',
'mychk','chkval'],'target');" % URL(r=request,f='bg_find2')))
                     )
                )

    return dict(form=form, target=DIV(_id='target'))

def bg_find2():
     return request.var.chkval


On Aug 27, 3:44 pm, Jose <[email protected]> wrote:
> Hi,
>
> The follows is a simplification.
>
> If my controller is:
>
> def buscar():
>     form = FORM(TABLE(
>             TR(INPUT(_name='mytxt', _id='mytxt', _value='a text...')),
>             TR(INPUT(_type='checkbox', _name='mychk', _id='mychk',
> _value='')),
>             TR("", INPUT(_type="submit",_value="Buscar"))
>             ))
>
>     if form.accepts(request.vars, session, keepvalues=True):
>         if request.vars.mychk:
>             ...
>             ...
>         rows = db(query1 & query2).select()
>
>     return dict(form=form, rows=rows)
>
> When I send the form, I know the state of the checkbox on the line [if
> request.vars.mychk]. This works well!
>
> In the example below I can not get the same result, The condition is
> always true. This is because I is returning the value, which is always
> 'on', even though I put something else.
>
> def search2():
>     form = FORM(TABLE(
>             TR(INPUT(_name='mytxt', _id='mytxt', _value='a text...')),
>             TR(INPUT(_type='checkbox', _name='mychk', _id='mychk',
> _value='')),
>             TR("", INPUT(_type="button", _value="Buscar",
>                     _onclick="ajax('bg_find2',['mytxt', 'mychk'],
> 'target');"))
>             ))
>
>     return dict(form=form, target=DIV(_id='target'))
>
> def bg_find2():
>      if request.vars.mychk:
>         ...
>
>     return dict(txt=request.vars.mytxt, chk=request.vars.mychk)
>
> How can I access the checkbox checked property?
> Or more simply, how can I know the state of the checkbox in bg_find2
>
> Regards
> Jose
--~--~---------~--~----~------------~-------~--~----~
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