vendredi 28 août 2020

How to get value Check and Uncheck checkbox use JQuery on array

Now im doing PHP Project combine with JQuery. I want to get value from checkbox both checked and unchecked on array. here is what i try

$(function() {
      $('.dealprice').on('input', function(){

        if($('.dealprice:checkbox:checked').prop('checked')){
            //CHECKED
            console.log("Checked");
            const getPrice = $(this).closest("tr").find('input[name=itemprice]').val();
            console.log(getPrice);
        }else{
            //UNCHECKED
            console.log("Uncheck");
            const getPrice = $(this).closest("tr").find('input[name=itemprice]').val();
            console.log(getPrice); 
        }
        
    });
 });

i make a sample on this site. https://repl.it/@ferdinandgush/get-value-checkbox please click "RUN" bottom on the top to able test it.

the problem is, when the checkbox checked more then 1 and when i want to uncheck 1 of it. it still return value "True" not "false".

what i want it. each of checkbox can return value wherever i checked and uncheck it.

checked return consolo.log('true');

unchecked return consolo.log('false');

please help




Aucun commentaire:

Enregistrer un commentaire