thank you so much for your detail explaination anthony.
i've spent more time following your advice to learn about javascript/jquery 
and python through update my code but still not work (no error occured, but 
what i'm expected is not realize). the basic logic is when user click the 
button it will increase the quantity and update the total price (total = 
price per unit * quantity), i know there is some mistake in my code, but i 
don't know where. do you have any idea about this?

here is my updated code :
*controller : default.py*
def order_callback():
    id=int(request.vars.id)
    if request.vars.action=='add':
        session.order[id]=session.order.get(id, 0)+1
    if request.vars.action=='subtract':
        session.order[id]=max(0,session.order.get(id, 0)-1)
    return str(session.order[id])

def order_reload():
    qty=int(request.vars.qty)
    price=int(request.vars.price)
    total=qty*price
    return dict(total=total)

*view : order.html*
<table width="100%">
{{for id, qty in order.items():}}
{{p=db.product(id)}}
    <tr>
        <td>{{=SPAN(p.product_name)}}</td>
        <td>{{=SPAN('Rp. %s' % p.unit_price)}}</td>
        <td>{{=SPAN(qty, _id='item_%s' % p.id)}}</td>
        <td>{{=SPAN(qty*p.unit_price, _id='total_%s' % p.id)}}</td>
        <td>{{=SPAN(A('Add', callback=URL('order_callback', 
vars=dict(id=p.id, action='add')), target='item_%s' % p.id, _title='Add 
Quantity', _class='btn btn-navbar'))}} {{=SPAN(A('Subtract', 
callback=URL('order_callback', vars=dict(id=p.id, action='subtract')), 
target='item_%s' % p.id, _title='Substract Quantity', _class='btn 
btn-navbar'))}}</td>
    </tr>

<script>
jQuery(document).ready(function(){
   jQuery('#item_{{=p.id}}').change(function(){
        ajax('{{=URL('order_reload', vars=dict(qty=qty, 
price=p.unit_price))}}', '', 'total_{{=p.id}}'));
});
</script>
{{pass}}
</table>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to