Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get unchecked checkbox value.? with Id condition.?

Actually I am trying to get all unchecked checkbox value but where title = 1 condition..please help.my jquery code is.

var uncheckedValues = $('input[type="checkbox"][name="ing[]"][title= "1"]:not(:checked)').map(function() { return this.value; }).get();

and my checkbox code is

 <input class="badgebox" type="checkbox" onClick="addprice(<?php echo $total; ?>,<?php echo $addingri->id; ?>,'<?php echo $pprod_material->name; ?>')" id="<?php echo $addingri->id; ?>" value="<?php echo $pprod_material->id; ?>*<?php echo $addingri->price; ?>*<?php echo $addingri->name; ?>" name="ing[]" <?php if($pprod_material->id == 1) {  echo "checked";} ?>  title="<?php echo $pprod_material->id; ?>" >
like image 504
solanki Avatar asked Nov 20 '25 08:11

solanki


1 Answers

Use $("input[type='checkbox'][name='ing[]'][title= '1']:not(:checked)") selector to get all the unchecked checkbox having title="1".

Please check below working snippet.

$(document).ready(function(){
  //On page load
  uncheckedChk();

  //on checkbox change
  $("input[type='checkbox'][name='ing[]'][title= '1']").on("change",function(){
    uncheckedChk();
  });
});

//Function to identify all the unchecked checkbox with title=1
function uncheckedChk(){
  var not_checked = []
  $("input[type='checkbox'][name='ing[]'][title= '1']:not(:checked)").each(function (){
    not_checked.push($(this).val());
  });
  console.log(not_checked);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="ing[]" value="check-1" title="1" checked><br/>
<input type="checkbox" name="ing[]" value="check-2" title="1" checked><br/>
<input type="checkbox" name="ing[]" value="check-2" title="1" ><br/>
<input type="checkbox" name="ing[]" value="check-3" title="1"><br/>
<input type="checkbox" name="ing[]" value="check-4" title="2" ><br/>
<input type="checkbox" name="ing[]" value="check-5" title="1" ><br/>
like image 141
Rahul Patel Avatar answered Nov 21 '25 21:11

Rahul Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!