How to add an on select event to a drop down list box and pass the selected value to the js fuction?

37 views
Skip to first unread message

João Matos

unread,
Mar 22, 2019, 9:25:36 AM3/22/19
to web2py-users
Hello,

I have the form below and would like that when a user selects an equipment the page would reload with the equipment_id as an arg.
I know how to reload the page in javascript, but how can I add something similar to _OnClick (in this case a better name would be _OnSelect) to the drop-down list box created by the Field()?
And how can I pass the selected equipment_id to the javascript function?

   form = SQLFORM.factory(
       
Field('code', label=T('WO Code'), requires=IS_EMPTY_OR(
            IS_IN_DB
(db(query), 'wo.code', distinct=True))),
       
Field('client_id',
              label
=T('Client'),
              requires
=IS_IN_DB(db, 'client.id', '%(name)s', zero=T('Choose one...')),
       
),
       
Field('equipment_id',
              label
=T('Equipment'),
              requires
=IS_IN_DB(db, 'equipment.id', '%(name)s', zero=T('Choose one...')),
       
),
   
...



Thanks,

JM

João Matos

unread,
Mar 22, 2019, 11:45:35 AM3/22/19
to web2py-users
Found the solution.

form.element('#no_table_equipment_id')['_OnChange'] = 'reload_page(this.value);'


Reply all
Reply to author
Forward
0 new messages