I'm creating a web page which has two dropdown lists. one is for 'ID' and other is for 'Name'. when the user selects an ID, corresponding 'Name' should appear in the other drop-down list and vise-versa. both ID and Name fields are in the same table in my mysql database. i have created the drop down lists, but i have troubles in populating them dynamiccaly according to values selected (since i'm bad in javascript and related techniques).
Assuming the option
s in the select
are in the same order, you can synchronize them when one changes. Take care to make sure that your synchronization change doesn't trigger another change.
Use the selectedIndex
property to get and set the selected index of each select
. You can use getElementById
to retrieve a particular element. Use addEventListener
to add a listener for the change
event.