dolythgoe
asked on
Disable/Enable checkboxes using jQuery and special cases
Hi all,
I have this code working well (thanks to leakim):
This ajax call returns a set of values after sending a set of values via queryString variable.
Now, I have a load of checkboxes:
The value is split into 2, first part being the group_id and the second being the option_id
The jquery code above is used to disable any checkboxes that are NOT in the returned string from the AJAX call.
I need to amend this code based on value as opposed to id and extend it to do the following.
- Depending on the group_id in the first part of the queryString var, only make those appliceable for disabling that do not belong to this group.
- Do not disable any checkboxes already checked
An example of queryString var might be:
filter_options=1-1,1-2,1-5 ,2-6,2-10, 3-15,3-16
([group_id]-[option-id])
Return value is just option_ids which are appliceable for further filtering: 16,17,18,19 etc..
So I need to adjust my code to:
- Extract the group_id from the first value in queryString
- Run trhough the checkboxes and disable those not in the returned value (except those that belong to the first group_id and those that are already selected)
Hope that makes sense, bit hard to explain!
huge thanks
I have this code working well (thanks to leakim):
$.disableFilter = function(queryString)
{
var url = "getTags.php" + queryString;
$.get(url, function(filterdata) {
var arr = filterdata.split(",");
$(":checkbox", "#filter_column").each(function() {
if( $.inArray($(this).attr("id"), arr) == -1 ) {
$(this).attr("disabled", true);
}
else {
$(this).attr("disabled", false);
}
})
});
}
This ajax call returns a set of values after sending a set of values via queryString variable.
Now, I have a load of checkboxes:
<input type="checkbox" onClick="ajaxFunction();" name="filter_option[]" value="25-436 />
<input type="checkbox" onClick="ajaxFunction();" name="filter_option[]" value="25-437 />
<input type="checkbox" onClick="ajaxFunction();" name="filter_option[]" value="25-438 />
<input type="checkbox" onClick="ajaxFunction();" name="filter_option[]" value="26-449 />
...more...
The value is split into 2, first part being the group_id and the second being the option_id
The jquery code above is used to disable any checkboxes that are NOT in the returned string from the AJAX call.
I need to amend this code based on value as opposed to id and extend it to do the following.
- Depending on the group_id in the first part of the queryString var, only make those appliceable for disabling that do not belong to this group.
- Do not disable any checkboxes already checked
An example of queryString var might be:
filter_options=1-1,1-2,1-5
([group_id]-[option-id])
Return value is just option_ids which are appliceable for further filtering: 16,17,18,19 etc..
So I need to adjust my code to:
- Extract the group_id from the first value in queryString
- Run trhough the checkboxes and disable those not in the returned value (except those that belong to the first group_id and those that are already selected)
Hope that makes sense, bit hard to explain!
huge thanks
ASKER
Hey, thanks for that.
What's the var belongs? This code appears to work except it doesn't meet the 2 conditions:
- ignore those that belong to the first group_id of queryString
- ignore those that are already selected
Any further help is much appreciated.
What's the var belongs? This code appears to work except it doesn't meet the 2 conditions:
- ignore those that belong to the first group_id of queryString
- ignore those that are already selected
Any further help is much appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot for this :D
by the way your asked what means that var :
is for caching purpose, so then you dont need to request DOM with $(this)... several times.
var self = $(this);
is for caching purpose, so then you dont need to request DOM with $(this)... several times.
Open in new window