I have several checkboxes and radio Buttons with same class that user is able to select one of the radio Buttons and multi checkboxes.

after checking one of them i hold sum of amount by amount attribute in variable and after unchecked checkbox i reduce amount from sum value but How to find the radio attributes that is unselect after choosing one of radio buttons to reduce from sum variable?

<input type="radio" class="form-control selected-tuitions" name="selected-tuitions[]" value="70" amount="8600000" allow-count="0" interval="0" section="2" pre-payment="8600000">

2 Answers

0
VoidZA On

So the problem will be that only the selected input will be sent in your $_POST, so if you want to access the unselected in PHP it is a bit tricky. You can use jQuery to get the values of the unselected radios, and then store it in a hidden input which will then get posted.

//Add this input to your form
<input type="hidden" name="unselected-tuitions" id="unselected-tuitions">

//When the radio buttons gets clicked
$(document).on('click', '.selected-tuitions' function() {
    getUnselectedTuitions()
});

function getUnselectedTuitions() {
    let unselectedValues = [];
    //Loop through each of the unselected radio items
    $( "input.selected-tuitions:not(:checked)" ).each(function(){
        unselectedValues.push($(this).val());
    });
    //Store all the unselected values in our hidden input
    $("#unselected-tuitions").val(unselectedValues.toString());
}

So now you will have a hidden input with all the unselected values, which will be in the $_POST variable.

0
Morteza Mousavi On

you can try this code:

$('input[type="radio"]').not(':checked').each(function(){

    //Your Code

});