I am trying to learn how to use jQuery and I stumbled upon this code and the requirements below:

  • disable all the cells from "Every Monday" till "Every Sunday" as the initial status;
  • make "Never" exclusive from all the rest of options in the same row;
  • make "Less often", "Monthly" and "Weekly" exclusive each other;
  • when "weekly" is selected, eable the cells from "Every Monday" till "Every Sunday", and you can select more than one answer;
  • when "weekly" is deselected, disable the cells from "Every Monday" till "Every Sunday", and deselect all these cells.

Here is the fiddle with the code: Click Here

So far I figured how to solve the fourth requirement, but apply it for a single row..

$(function() {
  enable_cb();
  $("#group1").click(enable_cb);

});

function enable_cb() {
  if (this.checked) {
    $("input.group1").removeAttr("disabled");
  } else {
    $("input.group1").attr("disabled", true);

  }
}

Nevertheless, I have several rows so I thought I would make a group ID for each of the "Weekly" checkbox and then the following boxes to be part of that same class. How can I deal with checkboxes on all rows? Should I assign each checkbox a class and then work with that? What would be the best solution?

Should I assign each checkbox a class and then work with that?

Yes, that is usually the best option.

Yes, that is usually the best option. Here
Is there any other way of doing it?

What about if I make a group of all the "Every.." and disable it.
Then if checkbox "Weekly" is clicked, given its id, being the id of the group, enable the "Every.." group. Then give all the less monthly and weekly the same name, and make them mutually exclusive? How would I do this, making them mutually exclusive, without using radio buttons.

How do you usually deal with checkboxes in tables? Like you can affect a single row, but how do you apply it to all of them? For example if you click on second row, the checkbox on weekly, to enable all of the checkboxes that follow on the same row?

Find the checkbox's parent row (.closest('tr')), then use that node to find all it's checkbox children.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.