Zain
Zain

Reputation: 285

On clicking Button the checkbox should get disabled

. .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

Answers (5)

Somnath Kharat
Somnath Kharat

Reputation: 3610

Do this: attr()

$("#addtocart").click(function(){
    $("#option").attr("disabled",true);
}); 

OR

$("#option").attr("disabled","disabled");

OR

$("#option").removeAttr("disabled");

DEMO

Upvotes: 1

Thirumalai Parthasarathi
Thirumalai Parthasarathi

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

S. S. Rawat
S. S. Rawat

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

tymeJV
tymeJV

Reputation: 104795

You can do:

$("#addtocart").click(function() {
    var cb       = $("#option");
        isActive = cb.prop("disabled");

    cb.prop("disabled", !isActive);
});

Upvotes: 1

Rituraj ratan
Rituraj ratan

Reputation: 10388

$("#addtocart").toggle(function(){
$("#option").attr("disabled","disabled");
},function(){
$("#option").removeAttr("disabled");
});

reference toggle and attr

Upvotes: 2

Related Questions