'How to disable buttons in a certain combination with jquery?
I have 5 Buttons that are grouped in two groups:
// group 1
<button type="button" typenumber="1" typeelement="0">blank </button>
<button type="button" typenumber="1" typeelement="1">red </button>
<button type="button" typenumber="1" typeelement="2">blue </button>
//group 2
<button type="button" typenumber="2" typeelement="0">without extra </button>
<button type="button" typenumber="2" typeelement="1">with extra </button>
In this example "blank" shoud not go with "extra". So I like to disable the button "extra" when "blank" is chosen and the button "blank" when "extra" is chosen
These combination is defined in an object:
{"1":["/blank"],"2":{"1":"/extra"}}
where as "blank" has the typeNumber 1 and the typeElement 0 and "extra" has the typeNumber 2 and the typeElement 1
so i loop the object width this script:
var jsonTypeNumber = data.html.jsonTypeNumber; // is from 1 to 2
var jsonTypeElement = data.html.jsonTypeElement; // is from 0 to 2
var objDisabled = data.html.setDisabled;
alert(JSON.stringify(objDisabled)) // is {"1":["/blank_dessiniert"],"2":{"1":"/mit-vlies"}}
$.each(objDisabled, function( key, value ) {
if(jsonTypeNumber != key) {
$.each(value, function (key2, value2) {
if(jsonTypeElement != key2)
alert('not available')
else
alert('availabel')
});
}
});
It works but not with the third button from group 1 (blue). Has anyone an idea how to solve this in a fine way?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
