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
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Dynamic dropdown ?
Re: Dynamic dropdown ?
MaxGQC,
Run this populate_select() onchange of the_maker.
Steven
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>");
}
}
-
- Posts: 2
- Joined: Sun Nov 16, 2014 1:21 pm
Re: Dynamic dropdown ?
Thanks for your answer but I need to get the value in the dropdown from a db table, not hard coded
-
- Posts: 79
- Joined: Thu Oct 20, 2011 9:13 pm
Re: Dynamic dropdown ?
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
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
-
- Posts: 27
- Joined: Wed Dec 03, 2014 7:41 am
-
- Posts: 10
- Joined: Wed Apr 22, 2015 9:50 am
Re: Dynamic dropdown ?
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
Do you have a working example with mysql ? because I am very interested in this feature.
Thank you very much for your help.
Jacky
-
- Posts: 10
- Joined: Wed Apr 22, 2015 9:50 am
Re: Dynamic dropdown ?
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
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 ?
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
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