Jump to content

How to mark checkboxes by marking on other checkboxes


smus

Recommended Posts

I've got a form with checkboxes each of one has been generating from mysql-table data. I need to check the certain checkbox by checking another one according to the data values from the mysql-data. I've started to write a code that collects the data into an array. Could someone explain how to catch it in a JS function that will check the appropriate checkboxes?

Link to comment
Share on other sites

When the user checkes another checkbox. The list of checkboxes that I'm trying to check can have several values (1 or more). Each value corresponds to a so called general checkbox of another group that user checkes so that not to check each checkbox from the large list. In other words, each CB of the general list unites the group of checkboxes of another list by the identical values.

I've created a function that successfully checkes the CB(using JQuery $.post method), however it is not able to do two things: uncheck the corresponding checkboxes if user uncheckes the checkbox(retroaction) and does not consider that each of CB may have several values.

Link to comment
Share on other sites

In general, you need to put a click handler on each checkbox. The click handler can determine if the box is checked or unchecked, and then go from there. You can set data attributes on each checkbox if you want to store information about what should happen when it is checked or unchecked.

Link to comment
Share on other sites

Just break it down into pieces. Start with just putting a click handler on the checkboxes to run a Javascript function. Each checkbox will need an ID if you're going to be changing them. The click handler can get the checkbox that was clicked, and each checkbox will have a property called checked that is true or false for whether it is checked. There should be several examples online about how to do all of that. Data attributes are new in HTML 5, but once you get the click handlers working and checking the box that was clicked then you can move on to the stuff with the data attributes.

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...