You can but not this way.

You need the onlick to perform an ajax request.

This requires a new controller action:

def check():
    part_id=request.args(1)
    if not db((db.prodj_refs.prodj_id=request.args(0))& \
                  (db.prodj_refs.part_id=part_id)).delete()
                  return 'jQuery('#selector%i' % part_id).html('not
selected')
    else:
          db.prodj_refs.insert(prodj_id=request.args
(0),part_id=part_id)
          return 'jQuery('#selector%i' % part_id).html('selected')

and a view that calls the action via onclick and gets a response that
modified the page accordingly:

<table width="100%" cellpadding="1" cellspacing="0" border="0"
class="display" id="example">
                        <thead>
                        <tr>
                        <th>Part Name</th><th>Content</th><th>Number</
th><th>Created On</
th>
                        </tr>
                        </thead>
                        <tfoot>
                        <tr>
                        <th>Part Name</th><th>Content</th><th>Number</
th><th>Created On</
th>
                        </tr>
                        </tfoot>
                        <tbody>
                        {{for part in parts:}}
                        <tr>
                        <td>{{=part.part_name}}</td>
                        <td>{{=part.part_content}}</td>
                        <td>{{=part.part_number}}</td>
                        <td>{{=part.timestamp.year}}</td>
                        <td>
                        <button id="selector{{=part.id}}"
                          onclick="{{=URL(r=request,f='check',args=
[prodj.id,part.id])}}">
                        {{if db((db.prodj_refs.prodj_id=request.args
(0))&(db.prodj_refs.part_id=part_id)).count():}}selected{{else:}}not
selected{{pass}}
                        </button>
                        </td>
                        </tr>
                        {{pass}}
                        </tbody>
                        </table>



On Aug 24, 6:31 am, murray3 <ch...@murraypost.net> wrote:
> is there a way to run some python db.update code in   a view by using
> the onclick event from the checkbox.
> At present the python code just runs, I put the "checker" in there to
> try and toggle it off until the onclick event obviously does not run
> the python code as is.
> help appreciated
> chrism
>
> <table width="100%" cellpadding="1" cellspacing="0" border="0"
> class="display" id="example">
>                         <thead>
>                         <tr>
>                         <th>Part 
> Name</th><th>Content</th><th>Number</th><th>Created On</
> th>
>                         </tr>
>                         </thead>
>                         <tfoot>
>                         <tr>
>                         <th>Part 
> Name</th><th>Content</th><th>Number</th><th>Created On</
> th>
>                         </tr>
>                         </tfoot>
>                         <tbody>
>                         {{for part in parts:}}
>                         {{checker=0}}
>                         <tr>
>                         <td>{{=part.part_name}}</td>
>                         <td>{{=part.part_content}}</td>
>                         <td>{{=part.part_number}}</td>
>                         <td>{{=part.timestamp.year}}</td>
>                         <td class="center"><input type="checkbox" 
> name="check_"
> value="{{part.id}}"                                   onclick="{{if not 
> checker==0:}}
> {{=db.prodj_refs.insert(prodj_id=prodj.id,part_id=part.id)}}
> {{pass}}"></td>
>                         </tr>
>                         {{pass}}
>                         {{checker=1}}
>                         {{pass}}
>                         </tbody>
>                         </table>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to