I have two radio button that are value 0 and 1 stored in mysql database after that i want to enable(when value is =1) or disable(when value is =0) button. i new to php please give me code for that some thing like that...
<input type="submit" ... <?php&nbs
p;if (/* condition not met */)
echo "disabled='disabled'" ?>">

Recommended Answers

All 7 Replies

Try This

<div>
  <label > Radio</label>
  <div>
    <input type="radio" name="r1" id="0" value="0"   <?php if(isset($rws['radio1']) && $rws['radio1'] =="0"){ ?> disable <?php }?>>
    Radio1
    <input type="radio" name="r1" id="1" value="1"  <?php if(isset($rws['radio2']) && $rws['radio2'] == "1"){?>  <?php }?>>
    Radio2 </div>
</div> 

Hi Ketul,
Thanks for reply but actualy i want this in diff. ways my program is like that
Page 1-
in that i have Two RADIO button that value is 0 and 1 stored in mysql database.
Page 2-
in that i have BUTTON to corresponding to Page 1 RADIO button, i want to enable/disable BUTTON corresponding to RADION button value (i.e. 1 or 0 stored in database) plz give me help.

I don't Understand Can u send me images?

ya can u send me ur email id so i will send u images

If you're posting the value of the radio to a different page, you might be over-complicating it by over-thinking it.

Page 2:

<?php
    // Posted value from Page 1
    $radio_value = $_POST['radio_element'];

    if($radio_value == 0) {
        <button type="button" disabled>You can't click me!</button>
    } else {
        <button type="button">Click away!</button>
    }
?>

Using what the guys have said about obtaining the $radio variable:

Solution to your version

<input name="xyz" <?php if($radio == 0){echo "disabled='disabled'";} ?> />

Neater version

<?php

$input = "<input name='xyz'";

if($radio == 0)
{
    $input .= " disabled='disabled'";
}

$input .= " />";

echo $input;

?>

Hi mattster,
Thanks Very much Its Working ur code Thanks again see u again.
i want know where r u from ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.