Reputation: 285
. .On clicking a button the checkbox should get disabled and clicking back again the checkbox should get enabled. . .as i dono much about javascript or jquery. . .please help. . .
<input id="option" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/>
<input type="button" class="button2" id="addtocart" value="Add to Cart" Title="Add to Cart" onClick="addItem_check('item_listing_100','ItemTable','100','Amul Butter','500','g','150.00','1','kg','200.00','2','kg','250.00'); amul1.style.backgroundColor='#c2ed5c'; if(this.value=='Add to Cart') {this.value = 'Remove from Cart'};"/>
Upvotes: 0
Views: 335
Reputation: 3610
Do this: attr()
$("#addtocart").click(function(){
$("#option").attr("disabled",true);
});
OR
$("#option").attr("disabled","disabled");
OR
$("#option").removeAttr("disabled");
Upvotes: 1
Reputation: 4671
This would do the trick
<!DOCTYPE html>
<html>
<head>
<script>
var x = true;
function toggle()
{
if(x) {
x=false;
document.getElementById("chk1").disabled=true;
} else {
x=true;
document.getElementById("chk1").disabled=false;
}
}
</script>
</head>
<body>
<input type="checkbox" id="chk1">
<button type="button" onclick="toggle()">Toggle</button>
</body>
</html>
Upvotes: 1
Reputation: 6131
Try this
, this is helpfull for you
JS
$("#addtocart").click(function(){
if($("#option").prop("disabled"))
$("#option").prop("disabled",false);
else
$("#option").prop("disabled",true);
});
Upvotes: 1
Reputation: 104795
You can do:
$("#addtocart").click(function() {
var cb = $("#option");
isActive = cb.prop("disabled");
cb.prop("disabled", !isActive);
});
Upvotes: 1
Reputation: 10388
$("#addtocart").toggle(function(){
$("#option").attr("disabled","disabled");
},function(){
$("#option").removeAttr("disabled");
});
Upvotes: 2