Page 1 of 1
Dynamic dropdown ?
Posted: Sun Nov 16, 2014 1:26 pm
by MaxGQC
Hi
I want to add a dropdown on my form and make the content change dynamically based on the selection of another dropdown
I have 2 table:
maker
id | maker_name
1 | Lenovo
2 | HP
model
id | name | maker
1 | Thinkpad | 1
2 | Probook | 2
1 | Thinkcentre | 1
In the form, if I select Lenovo as the maker, the choices on the 2nd dropdown are Thinkpad and Thinkcentre
I've been able to do it but I had to save the record before the content of the 2nd dropdown changes
How can I do this ?
Thanks and sorry for my bad english
Re: Dynamic dropdown ?
Posted: Sun Nov 16, 2014 11:02 pm
by admin
MaxGQC,
Run this
populate_select() onchange of
the_maker.
Code: Select all
function populate_select(){
$("#the_dropdown option").remove();
$("#the_dropdown").append("<option value=''></option>");
if($('#the_maker').val() == '1'){
$("#the_dropdown").append("<option value='thinkpad'>Thinkpad</option>");
$("#the_dropdown").append("<option value='thinkcentre'>Thinkcentre</option>");
}
if($('#the_maker').val() == '2'){
$("#the_dropdown").append("<option value='probook'>Probook</option>");
}
}
Steven
Re: Dynamic dropdown ?
Posted: Mon Nov 17, 2014 2:49 am
by MaxGQC
Thanks for your answer but I need to get the value in the dropdown from a db table, not hard coded
Re: Dynamic dropdown ?
Posted: Fri Nov 21, 2014 4:57 pm
by Fike
Hi,
I have done that using a (hidden) subform that contains the records of the table from which you want to get the values.
You would need to adapt the JavaScript function provided by Steven in order to get the values from that subform, and execute the function when the 'Marker' is selected using an onchange event.
Hope this helps.
Regrads,
Fike
Re: Dynamic dropdown ?
Posted: Thu Dec 04, 2014 12:15 pm
by nekpap
Hi,
How do you refresh the subform?
Nektarios
Re: Dynamic dropdown ?
Posted: Fri Apr 24, 2015 10:30 am
by jacky
Hello,
Do you have a working example with mysql ? because I am very interested in this feature.
Thank you very much for your help.
Jacky
Re: Dynamic dropdown ?
Posted: Sun Apr 26, 2015 12:04 pm
by jacky
Hello,
I managed to run the example above.
Unfortunately I am in subform, how to automatically determine the names of the marker and dropdown ?
Thanks,
Jacky
Re: Dynamic dropdown ?
Posted: Mon Apr 27, 2015 2:07 am
by admin
jacky,
A Lookup Object can be used to give a filtered list based on a Form Object that might or might not change before the Form is saved.
http://wiki.nubuilder.net/index.php/Add ... Lookup_Tab
Steven