Using Ja开发者_JAVA技巧vascript / jQuery, I'm trying to build a "combination checker" that will take the values of three (but can be more) dropdown lists and filter the options based on a supplied list of allowed combinations.
For example:
DROPDOWNS
Field 1: - value_1 - value_2Field 2:
- value_3Field 3:
- value_4 - value_5COMBINATIONS
- value_1, value_3, value_5 - value_1, value_3, value_4 - value_2, value_3, value_5When a user selects Field 3 - value_4, the unavailable options will be disabled - ie, Field 1 - value_2 (there is no combination that allows value_2 and value_4 to be selected together).
It would be really great if someone could provide some pointers on how this can be achieved or just provide a fresh perspective - I'm going round in circles on this one!
You can keep the valid combinations in a javascript array.
var combinations = [[value1, value3, value5], [value1, value3, value4], [value2, value3, value5]];
You can then monitor changes with the jQuery change event and remove all entries in the dropdown, and then add the permitted entries only.
There is no way to disable a dropdown entry in particular (you can only disable/enable the whole dropdown), so you'll have to remove the non allowed ones.
精彩评论