Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i want to click a checkbox then the checkbox will be checked if i click again to checkbox that will not be unchecked and if i take a button and click the button that checkbox can be unchecked

What I have tried:

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


<input type="checkbox" id="cbx2"
CHECKED DISABLED/> disabled
</BODY>
</HTML>
Posted
Updated 28-Mar-16 18:47pm

Hello, Friend try this JQuery

$(document).ready(function(){
if($('#s:checked').length){
$('#sr').attr('readonly',true); // On Load, should it be read only?
}

$('#s').change(function(){
if($('#s:checked').length){
$('#sr').attr('readonly',true); //If checked - Read only
}else{
$('#sr').attr('readonly',false);//Not Checked - Normal
}
});
});
 
Share this answer
 
Comments
Rakib Ahmed 29-Mar-16 0:55am    
thanks for your help..:)
Try this


<HTML>
<HEAD>
<SCRIPT>
function readOnlyCheckBox() {
var checkbox = document.getElementById('cbx1');
checkbox.disabled = false;

return false;
}

function changeaction(obj)
{
debugger;
var isChecked = obj.checked;
if (isChecked)
{
obj.disabled = true;
}
}

</SCRIPT>
<BODY>
<input type="checkbox" id="cbx1" onchange="changeaction(this)" /> readonly

<button onclick="readOnlyCheckBox(); "> button </button>


</BODY>
</HTML>
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900