Home > Net >  how to stop checkbox from getting checked when confirm box cancel is clicked?
how to stop checkbox from getting checked when confirm box cancel is clicked?

Time:07-13

When clicking cancel I need the checkbox to go back to unchecked. But it's getting checked . I tried everything .

function ActivateReg(bID, cID, crID) {
  console.log(bID, cID, crID);
  var result = confirm("Do you really sure?");
  if (result) {
    //$ajax({ ajax call 
  } else {
    $("#chkbox"   bID).prop("checked", false); // not working
  }

  /* else
  {
  $("#chkbox"   bID  cID  crID).prop("checked", false);      // not working 
  }
  */
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" id="chkbox" onclick="ActivateReg('   item.as   ','   item.bs   ','   item.cs   ')"  />

CodePudding user response:

Ensure that you are pointing to correct checkbox with the selector.

Your checkbox id is chkbox and you are trying to point some other elements with "#chkbox" bID where bID is not needed I suppose.

It works fine without that bID parameter.

function ActivateReg() {
    var result = confirm("Do you really sure?");
    if (result) {
    } else {
        $("#chkbox").prop("checked", false);
    }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<input
    type="checkbox"
    id="chkbox"
    onclick="ActivateReg()"
    
  />

CodePudding user response:

you may include autocomplete='off' in your input tag. I had same type of issue which I solved by using this attribute

  • Related