The web2py book uses the following example to demonstrate how to call the ajax 
function in the views page. 

*Controller*:

def one():
    return dict()

def echo():
    return request.vars.name

*Views:*

{{extend 'layout.html'}}
<form>
   <input name="name" onkeyup="ajax('echo', ['name'], 'target')" />
</form>
<div id="target"></div>

However,I would like to know what modifications to above code would need to be 
made in order for the ajax function to work with the built in
forms function, instead of writing out the html input fields?

So for example, I have the following code below.

Model:

db.define_table('product',
                Field('quantity', 'integer'),
                Field('price', 'integer'))

Controller:

def product_form():
    form = SQLFORM(db.product)
    if form.process().accepted:
        session.flash = 'form accepted'
        redirect(URL('next_page'))
    return dict(form=form)

def total_cost():
    price = request.vars.price
    quantity = request.vars.quantity
    total = int(price) * int(quantity)
    return total

Views:

 {=form}

How can I modify the code below with the code I have above?
 
*{{extend 'layout.html'}}
<form>
   <input name="name" onkeyup="ajax('echo', ['name'], 'target')" />
</form>
<div id="target"></div>*

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to