I want to have a jquery function that will be activated when any checkbox is clicked and based on the value field of the checkbox that is clicked it will disable or enable other checkboxes.
So far I have:
$(function () {
$('input [type="checkbox"]').click(function () {
});
});
Okay, so I've made some progress.. but it's still not working.
<script type="text/javascript">
$(function () {
$(':checkbox').click(function () {
$value = $(this).attr('value');
if ($(this).is(':checked'))
{
switch ($value)
{
case "BLIPA":
$(':checkbox[value*="B"]').attr('disabled', true);
}
}
else
{
$(':checkbox').each(function()
{
}
}
});
});
Have I made any mistakes?
Edit:
Okay so I have solve it. Here is the solution:
<script type="text/javascript">
$(function () {
$("input[type='checkbox']").click(function () {
var value = $(this).attr('value');
if ($(this).is(':checked')) {
var modules = FindModuleRules(value);
$(':checkbox[value*="' + modules[0] + '"]').attr('disabled', true);
$(':checkbox[value*="' + modules[1] + '"]').attr('disabled', true);
$(':checkbox[value*="' + modules[2] + '"]').attr('disabled', true);
$(':checkbox[value~="' + value + '"]').attr('disabled', false);
}
else {
var modules = FindModuleRules(value);
$(':checkbox[value*="' + modules[0] + '"]').attr('disabled', false);
$(':checkbox[value*="' + modules[1] + '"]').attr('disabled', false);
$(':checkbox[value*="' + modules[2] + '"]').attr('disabled', false);
}
});
function FindModuleRules(string) {
var modules = new Array();
var bRegex = /B/;
var lRegex = /L/;
var aRegex = /A/;
if (string.search(bRegex) != -1)
modules[0] = "B";
else
modules[0] = "X";
if (string.search(lRegex) != -1)
modules[1] = "L";
else
modules[1] = "X";
if (string.search(aRegex) != -1)
modules[2] = "A";
else
modules[2] = "X";
return modules;
}
});