I have been searching and reading and experimenting for 3 days now. This
is driving me crazy and I know I am missing something fundamental as I am a
noob.
I want to have the user input several integers, add them up and put them in
a total field on the form before the submit to the database. In the real
app this is important for sanity checks. I plan to make the total
non-writeable by the user as well.
The test code I have tried is below, ripped from an old thread here, and
returns NaN for the total - not a number. I am pretty sure val() is
converting it to a string but can't find out how to stop it, or an
alternative way to get the total into total
I really want to use this in a custom form using the widgets but figured if
I couldn't even make it work with this simple test, then I have no hope of
a more complex approach.
Help please.
Model
db.define_table('additup',
Field('number1','integer', default = 0),
Field('number2','integer',default = 0),
Field('number3','integer', default = 0),
Field('total','integer', default = 0))
Controller
def index():
form = SQLFORM(db.additup)
return locals()
View
{{extend 'layout.html'}}
{{=form}}
<script>
jQuery("input[name='number1'],input[name='number2'],input[name='number2']").change(function()
{
jQuery("input[name='total',]").val(parseInt(jQuery("input[name='number1']"))+parseInt(jQuery("input[name='number2']"))+parseInt(jQuery("input[name='number3']")));
});
</script>
--
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/d/optout.