How would I disable specific input elements based on the value of a PHP variable?
Example HTML
<?php
$stock_count = 1;
?>
<td width="252" valign="top">
<a href="action-sale.php?size=<?=$size_quantity?>_con_b&id=<?=$product['product_id'];?>&barcode=<?=$barcode?>&shop_price=<?=$product['price']?>&brand=<?=$product['brand_id']?>&title=<?=$product['title']?>">
<input name="button5" type="submit" class="submit-button-green"
id="sale" value="CONCESSION PRODUCT SOLD" style="width:100%" onclick="this.disabled=1;"/>
</a>
</td>
<td align="right">
<a href="action-delivery.php?size=<?=$size_quantity?>_con_b&id=<?=$product['product_id'];?>&barcode=<?=$barcode?>">
<input name="button" type="submit" class="submit-button"
id="delivery" value="PRODUCT DELIVERED" style="width:170px" onclick="this.disabled=1;"/>
</a>
</td>
Condition
IF ($stock_count <= 0)
{
Disable ID 'Sale'
}
ELSE IF ($stock_count > 0)
{
Do not disable anything
}
So based on the condition above the disabled attribute would be added to the sale input button. If the value of the $stock_count variable is greater than 0 than no action will be needed.
Any advice appreciated. Thanks
UPDATE
I managed to solve the issue with the following code:
$disabled = $stock_count > 0 ? "" : "disabled";
<input name="sale" type="submit" class="submit-button-green"
id="sale" value="PRODUCT SOLD" style="width:100%"
onclick="location.href='action-sale.php'"; <?php echo $disabled; ?> />