Check if a checkbox is ticked or not

Check if a checkbox is ticked or not

by anj m -
Number of replies: 5

How to check if a checkbox is ticked or not?..Generally,an 'if(isset($_POST())' would work,but instead of $_POST,what condition should be applied?

Average of ratings: -
In reply to anj m

Re: Check if a checkbox is ticked or not

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
If you at using a Moodle form, then $data = $form->get_data(); if ($data->checkboxname) { ...

If not, then: $check = optional_param('checkboxname', false, PARAM_BOOL);
In reply to Davo Smith

Re: Check if a checkbox is ticked or not

by anj m -

This works when i move to the next page after clicking the save button.But,i want to fetch the status of the checkbox as soon as the user checks or unchecks it.How can this be done?

In reply to anj m

Re: Check if a checkbox is ticked or not

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You'll need some javascript to do that, you'll have to be a lot more specific about what you're trying to do, in order for anyone to help any more than that.

In reply to Davo Smith

Re: Check if a checkbox is ticked or not

by anj m -

What i am looking for is ,when one checkbox is checked,i want other checkboxes to be checked simultaneously.Depending on the status of the checkbox,i want remaining checkboxes to be checked and unchecked.