Jump to content

checkboxes disable


anser316

Recommended Posts

Hi i have a checkbox form. It has a counter so the next form knows which are ticked.What I am trying to do is disable the checkbox if ($row2['total_stock']) =0. But i dont wont it to effect the counter. This is my code without disabling

$counter=0;
while($row2 = mysql_fetch_array( $result3 )) {
echo "<tr><td>";
echo "<input type='hidden' name=drug_id[$counter] value='$row2[drug_id]'>";
echo $row2['drug_id'];
echo "</td><td>";
echo "<input type='hidden' name=presc_id value='".$presc."'>";
echo $row2['drug_name'];
echo "</td><td>";
echo "<input type='hidden' name=dosage[$counter] value='$row2[dosage]'>";
echo $row2['dosage'];
echo "</td><td>";
echo "<input type='hidden' name=total_stock[$counter] value='$row2[total_stock]'>";
echo $row2['total_stock'];
echo "</td><td>";
echo "<input type=text name=quantity[$counter]>";
echo "</td><td>";
echo "<input type=checkbox name=ticked[] value='$counter'>";
echo "</td></tr>"; 
$counter++;
}
echo "</table>";
echo "<input type =submit name='adddrug' value= 'Add Drug'>";
echo "<input type = reset>";
echo "</form>";
}

 

This is what i changed it to, to get it diasable

$counter=0;
while($row2 = mysql_fetch_array( $result3 )) {
echo "<tr><td>";
echo "<input type='hidden' name=drug_id[$counter] value='$row2[drug_id]'>";
echo $row2['drug_id'];
echo "</td><td>";
echo "<input type='hidden' name=presc_id value='".$presc."'>";
echo $row2['drug_name'];
echo "</td><td>";
echo "<input type='hidden' name=dosage[$counter] value='$row2[dosage]'>";
echo $row2['dosage'];
echo "</td><td>";
echo "<input type='hidden' name=total_stock[$counter] value='$row2[total_stock]'>";
echo $row2['total_stock'];
echo "</td><td>";
echo "<input type=text name=quantity[$counter]>";
echo "</td><td>";
if (($row2['total_stock'])==0){
echo "<input type=checkbox disabled name=ticked[] value='$counter'>";}
else {
echo "<input type=checkbox name=ticked[] value='$counter'>";
}
echo "</td></tr>"; 
$counter++;
}
echo "</table>";
echo "<input type =submit name='adddrug' value= 'Add Drug'>";
echo "<input type = reset>";
echo "</form>";
}

 

It does not get disabled though.

Help will be appreciated thankyou

Link to comment
https://forums.phpfreaks.com/topic/101969-checkboxes-disable/
Share on other sites

I have just tried out your code with a few minor changes to the input values so I can test it

$test = 1;
if ($test==0){
echo "<input type=checkbox disabled name=ticked[] value='$counter'>";}
else {
echo "<input type=checkbox name=ticked[] value='$counter'>";
}

 

and if i change the value of $test it works just fine so I dont know why it wont work for you unless the values it checks against are awry somewhere along the line

Link to comment
https://forums.phpfreaks.com/topic/101969-checkboxes-disable/#findComment-522002
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.