I am getting request.vars as shown below when I print it vars: <Storage {'opt1': ['3', '3'], 'opt2': ['12 ', '18 '], 'opt3': ['1', '1'], 'txt1': ['1', '1']}>
these values are given as input from user interface and it has 2 rows, each row has 3 dropdown and 1 text box now how do I read each item and insert into database, in the database there is a table that has 4 columns, as per my requirement now it has to insert 2 records in that table On Friday, June 3, 2016 at 2:21:48 PM UTC-6, Anthony wrote: > On Friday, June 3, 2016 at 12:35:49 PM UTC-4, ktesr...@gmail.com > <javascript:> wrote: >> >> it is a single select, the values are populated from controller into a >> view dynamically in jquery >> > > OK, so what's wrong with your current approach? What are you trying to > achieve? Hard to help without seeing your code (e.g., model definitions, > etc.). Also, why are you using .getlist for a variable that isn't a list, > and then just extracting the first element (which you would get if not > using .getlist)? > > Anthony > > >> On Friday, June 3, 2016 at 6:32:34 AM UTC-6, Anthony wrote: >>> >>> Hard to say because it's not clear (a) what kind of data are in opt1, >>> opt2, etc. (are they multi-select widgets producing lists or just single >>> selects?) and (b) how the form inputs map to your database fields. >>> >>> Anthony >>> >>> On Thursday, June 2, 2016 at 11:55:13 PM UTC-4, ktesr...@gmail.com >>> wrote: >>>> >>>> Anthony >>>> >>>> I wanted to iterate all the values from request.vars these values are >>>> passed using ajax function from View, in the View each row will have 3 >>>> drop >>>> downs and 1 textbox to take input from user >>>> there can be minimum 1 row. I am passing all the control names thru >>>> ajax function >>>> >>>> View >>>> ======= >>>> <script> >>>> /* jquery that builds html form written here */ >>>> >>>> ajax('{{=URL('insert_data')}}',['opt1','opt2','opt3','txtt1'],'target'); >>>> // opt1, opt2 and opt3 are dropdown control names and txt1 is the name if >>>> textbox control all are html controls dynamically crated using jquery >>>> >>>> </script> >>>> <div id=...></div> >>>> <div id='target'></div> >>>> >>>> Controller >>>> ========== >>>> def insert_timesheet(): >>>> >>>> orglist = request.vars.getlist("opt1") >>>> response.flash = str(orgval) >>>> >>>> ##db.Table.insert(field1=opt1[0],.....) >>>> return locals() >>>> >>>> >>>> >>>> On Thursday, June 2, 2016 at 7:34:04 PM UTC-6, Anthony wrote: >>>> >>>>> Please show some code and explain exactly what you want to do. To get >>>>> a particular value from request.vars, just do >>>>> request.vars.name_of_variable. >>>>> >>>>> Anthony >>>>> >>>>> On Thursday, June 2, 2016 at 8:07:13 PM UTC-4, ktesr...@gmail.com >>>>> wrote: >>>>>> >>>>>> I am getting selected values from View to Controller using >>>>>> request.vars >>>>>> >>>>>> I can see the values are coming as key value pair but not able to >>>>>> figure out how to read each value and insert them in DB >>>>>> >>>>>> >>>>>> -- 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/d/optout.