Jump to content
Larry Ullman's Book Forums

Recommended Posts

<p><p>What is wrong with this code?

<?php
$Available=1;
...
<label>Currently Available?</label><br />
<input type=\"radio\" name=\"Available\" value=(if($Available==1){echo'checked=\"checked\"'})>Yes
<input type=\"radio\" name=\"Available\" value=(if($Available!=1){echo'checked=\"checked\"'})>No
?>

 

Whatever I do I cannot get any value to display in either option.

Link to comment
Share on other sites

Sorry, code should read:

<?php
$Available=1;
echo "<label>Currently Available?</label><br />
     <input type=\"radio\" name=\"Available\" 
            value=(if($Available==1){echo'checked=\"checked\"'})>Yes
     <input type=\"radio\" name=\"Available\" 
            value=(if($Available!=1){echo'checked=\"checked\"'})>No";
?>

Link to comment
Share on other sites

Checked is an attritbute of input type so it should not be within the value attribute. I think this is what you are trying to do

<form method="post" action="#">
<label>Currently Available?</label><br />
<input type="radio" name="Available" value="Yes"
<?php if (isset($_POST['Available']) && $_POST['Available'] == "Yes") echo 'checked="checked"';?>>Yes
<input type="radio" name="Available" value="No"
<?php if (isset($_POST['Available']) && $_POST['Available'] == "No") echo 'checked="checked"';?>>No
<input type="submit" name="submit" value="Submit">

</form>	

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...