Here is a small code snippet I wrote that I feel is pretty naive. I copied the code directly from my project and renamed some ID/class names.
I'd like to know how you could help to improve/refactor the code. radiobox1
and radiobox2
form a pair, and radiobox3
and radiobox4
form another pair - they're both mutually exclusive - which means select radiobox1
then radiobox2
is disabled, and vice versa. Then I will load the data in terms of the user's selection combination. In total, there are 4 selection combinations.
var viz = (function () {
var config = {
width: 960,
height:600,
big: true,
small: true,
index: 0
};
var emptyGraph = function () {
if (!$('#graph').is(':empty')) {
$("#graph").empty();
}
};
var bind = function () {
$("#radiobox1").change(function () {
if ($(this).is(':checked')) {
emptyGraph();
$("#radiobox2").prop("checked", false);
config.small = true;
loader.loadData(config);
}
});
$("#radiobox2").change(function () {
if ($(this).is(':checked')) {
emptyGraph();
$("#radiobox1").prop("checked", false);
config.small = false;
loader.loadData(config);
}
});
$("#radiobox3").change(function () {
if ($(this).is(':checked')) {
emptyGraph();
$("#radiobox4").prop("checked", false);
config.big = true;
loader.loadData(config);
}
});
$("#radiobox4").change(function () {
if ($(this).is(':checked')) {
emptyGraph();
$("#radiobox3").prop("checked", false);
config.big = false;
config.index = 1;
loader.loadData(config);
}
});
};
return {
init: bind,
}
})();
input
's the samename
(in your case, one name for a pair and another for the other) and the browser will make sure that only one is selected. Or am I misunderstanding something? \$\endgroup\$ – ᔕᖺᘎᕊ Aug 19 '15 at 11:18