How do i disable a button if the prod_quantity == 0?
<?php
$prod_qty = $row['prod_quantity'];
if ($prod_qty == '0'){
echo "<h1>sold out</h1>";
echo '
<input
type="button"
value="Add to Cart"
onclick="addtocart('.$row['prod_id'].')"
disabled
/>'
}else{
<input type="button" value="Add to Cart" onclick="addtocart(<?php echo $row["prod_id"]?>)" />
}
?>
if($prod_qty==0)
{
<?php
<input type="button" value="Add to Cart" disabled />
<?php
}
UPDATE 2 :
<input type="button" value="Add to Cart"
<?php if($row["prod_qty"]==0)
{
echo ' onclick="addtocart('.$row["prod_id"].')" ';
}
else
{
echo ' disabled=disabled ';
}
?>
/>
try this
javascript onclick function...
function addtocart(prod_qty){
var quantity=parseInt(prod_qty);
if (quantity == 0){
document.getElementById("addtocartButton").disabled = true;
}
}
your button
<input type="button" value="Add to Cart" id="addtocartButton" onclick="addtocart(<?php echo $row["prod_id"]?>)" />
Add an if
condition to the button to set the property as disabled
if $prod_qty == '0'
like shown below :
<input type="button" value="Add to Cart" <?php if ($prod_qty == '0'){ ?> disabled <?php } ?> onclick="addtocart(<?php echo $row["prod_id"]?>)" />