简体   繁体   English

使用Java脚本更改其他组合框的组合框的值

[英]Change the value of combo box of other combo box using Javascript

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 两个组合框的值是从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. 如果第一个组合框的值更改为“ Linux Admin”,则第二个组合框的值应显示指定的位置,具体取决于第一个组合框的值。

I found with the same function, but the values are manually populated Javascript - combobox change value of other combobox 我发现具有相同的功能,但值是手动填充的Javascript-组合框更改其他组合框的值

I've solved this before. 我之前已经解决了 I did this in an MVC C# application, but the idea would still work here. 我是在MVC C#应用程序中完成此操作的,但该想法在这里仍然适用。

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'. 在构建HTML时,请使用“ 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. 在javascript中,当第一个组合框发生更改时,请脚本从第一个组合框选择器中读取值,然后拆分这些值,并将其作为名称放入下一个组合框中。

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. 这是一个总体思路,我使用了一组选择框来选择Make,然后使用可用的模型填充下一个选择框。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM