Assume that a webpage is having list of names in one drop-down list and the corresponding ages in another drop-down list as below.
If you select “Name1” in the first drop-down list, corresponding value “Age1” will be selected in the second list box.
And, also if you select “Age2” in the second list then “Name2” will be selected automatically.
The HTML code will look like below for showing these two drop-down lists.
The setage function gets the selectedIndex value of Name list and assign this value as selected Index of age list.
setname also behaves similarly for changing name when age is changed.