0

I have two combo boxes in a form. The 1st combo box: type of position hiring while the 2nd combo box: location. The values of two combo boxes are dynamically populated from mysql

I need to change the value of 2nd combo box. If the value of 1st combo box change to "Linux Admin", the value of 2nd combo box should display the designated locations depends on the value of 1st combo box.

I found with the same function, but the values are manually populated Javascript - combobox change value of other combobox

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
User014019
  • 1,215
  • 8
  • 34
  • 66

1 Answers1

0

I've solved this before. I did this in an MVC C# application, but the idea would still work here.

When you are building your HTML, create the name-value pairs for the combo boxes with the Name (in one of your stated cases) as being 'Linux Admin'. In the value for that, put all the locations in as a tab-delimited string.

In the javascript, when the first combo box changes, have the script read the values from the first combobox selector and split those values and put them in the next combo box as the names.

Here is a general idea that I used for a set of select boxes to allow for the selection of a Make, and then the next select box be populated with the available models.

<select>
    <option value="Escape,Expedition,Explorer,F150,F350SD,Focus,Fusion,Mustang,T250 Vans">Ford</option>
    <option value="Acadia,Envoy XL,Sierra 1500,Sierra 2500 Clsc,Terrain,Yukon">GMC</option>
</select>
Joe
  • 37
  • 4