kristo5747 Posted April 8, 2010 Share Posted April 8, 2010 I'm coding a page form and to prevent its fields to be reset, I have to echo the POST values back into their respective form fields. It is working well for text inputs but I am having problem with four radio button inputs. Echo-ing the POST values back does not work: the respective form fields are always reset, blanked out...no matter what!! This is what I wrote... ...<td><fieldset> <legend>Frequency: </legend> <input type="radio" id="rad0" tabindex="8" name="Frequency" value="One Time" <?php echo $ontime_status; ?>>One Time<br> <input type="radio" id="rad1" tabindex="9" name="Frequency" value="Daily" <?php echo $dly_status; ?>>Daily<br> <input type="radio" id="rad2" tabindex="10" name="Frequency" value="Weekly" <?php echo $wky_status; ?>>Weekly<br> <input type="radio" id="rad3" tabindex="11" name="Frequency" value="Monthly" <?php echo $mthly_status; ?>>Monthly<br> <input type="radio" id="rad4" tabindex="12" name="Frequency" value="Ongoing" <?php echo $ongoing_status; ?>>Ongoing<br> </fieldset></td>... ... and my code... ...if (isset($_POST['Frequency'])) { $selected_radio = $_POST['Frequency']; if($selected_radio == 'One Time') { $ontime_status = 'checked'; } elseif($selected_radio == 'Daily') { $dly_status = 'checked'; } elseif($selected_radio == 'Weekly') { $wky_status = 'checked'; } elseif($selected_radio == 'Monthly') { $mthly_status = 'checked'; } elseif($selected_radio == 'Ongoing') { $ongoing_status = 'checked'; } }... What I am doing wrong?? Can someone please tell me?! Link to comment https://forums.phpfreaks.com/topic/198033-post-value-to-radio-button-input-fails/ Share on other sites More sharing options...
taquitosensei Posted April 8, 2010 Share Posted April 8, 2010 radio buttons - only one can be checked. You would use the checked attribute for the correct one instead of the value from the post data. e.g. <input type="radio" id="rad0" tabindex="8" name="Frequency" value="One Time" CHECKED>One Time<br> so... <input type="radio" id="rad0" tabindex="8" name="Frequency" value="One Time" <?php echo ($_POST['Frequency']=="One Time")?"CHECKED":""; ?>>One Time<br> <input type="radio" id="rad1" tabindex="9" name="Frequency" value="Daily" <?php echo ($_POST['Frequency']=="Daily":"CHECKED":""; ?>>Daily<br> <input type="radio" id="rad2" tabindex="10" name="Frequency" value="Weekly" <?php echo ($_POST['Frequency']=="Weekly")?"CHECKED":""; ?>>Weekly<br> <input type="radio" id="rad3" tabindex="11" name="Frequency" value="Monthly" <?php echo ($_POST['Frequency']=="Monthly")?"CHECKED":""; ?>>Monthly<br> <input type="radio" id="rad4" tabindex="12" name="Frequency" value="Ongoing" <?php echo ($_POST['Frequency']=="Ongoing")?"CHECKED":""; ?>>Ongoing<br> Link to comment https://forums.phpfreaks.com/topic/198033-post-value-to-radio-button-input-fails/#findComment-1039118 Share on other sites More sharing options...
kristo5747 Posted April 8, 2010 Author Share Posted April 8, 2010 AWESOME!! It worked. Thanks, man!! Link to comment https://forums.phpfreaks.com/topic/198033-post-value-to-radio-button-input-fails/#findComment-1039128 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.