0

i want to click a checkbox then the checkbox will be checked if i click again that will not be unchecked and if i take a button and click the button that checkbox can be unchecked

<HTML>
<HEAD>
<SCRIPT>
function readOnlyCheckBox() {
   return false;
}
</SCRIPT>
<BODY>
<input type="checkbox" id="cbx1"
  ` onClick="return readOnlyCheckBox()" CHECKED /> readonly
<br/>
<input type="checkbox" id="cbx2"
    CHECKED DISABLED/> disabled
</BODY>
</HTML>

this code does not satisfy my answerstrong text

2 Answers 2

1

Just do this by Jquery attr() and removeAttr() functions.

Html

<input type="checkbox" id="test">
<button class="btn">Uncheck</button>

Jquery

//for check
$("input").on("click", function() {
  $(this).prop('checked', true).attr("readonly")
});

//for uncheck
$(".btn").on("click", function() {
  $('input').prop('checked', false).removeAttr("readonly")
});

here is fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

vote up or tick to my answer it would be appreciate
0

You can have 2 functions like

function readOnlyCheckBox(el) {
  return el.checked;
}

function uncheck() {
  document.getElementById('cbx1').checked = false;
}
<input type="checkbox" id="cbx1" onClick="return readOnlyCheckBox(this)" CHECKED />readonly

<br/>
<button onclick="uncheck()">Uncheck</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.