Thanks Massimo,
I tried it, but the output is still blank. The modified code is below.
{{=form}}
<script>
jQuery('input[name=price]','input[name=quantity]').keyup(function(){ajax('cost',['price'],['quantity'],'target');});
</script>
On Sunday, February 2, 2014 4:12:14 PM UTC-5, Massimo Di Pierro wrote:
>
> try this:
>
>
> 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 str(total)
>
> Views:
>
> {{=form}}
>
> <script>
>
> jQuery('input[name=price]').keyup(function(){ajax('echo',['price'],'target');});
>
> </script>
>
>
>
>
> On Sunday, 2 February 2014 13:49:50 UTC-6, raferbop wrote:
>>
>>
>> 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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.