liomon41 Posted November 16, 2011 Share Posted November 16, 2011 <?php $goal = rand(1, 3); ?> <td><div align="left"> Goal</div></td> <td><label> <div align="center"> <input type="radio" name="goal_chk" id="radio2" value="1" <?php if($goal == "1") { echo "checked"; }?> /> </div> </label></td> <td><label> <div align="center"> <input name="goal_chk" type="radio" id="radio13" value="2" <?php if($goal == "2") { echo "checked"; }?> /> </div> </label></td> <td><label> <div align="center"> <input type="radio" name="goal_chk" id="radio23" value="3" <?php if($goal == "3") { echo "checked"; }?> /> </div> </label></td> </tr> i have a group of radio buttons whose value is checked randomly everytime you refresh the page, now that works fine, everytime you refresh the page the checked values moves randomly but the problem i have is getting the actual of a checked radio button. i have tried this... $goal_checked = $_POST['goal_chk']; echo $goal_checked; But nothing happens. Any ideas on how to make this possible. Thanks a lot you guys. Quote Link to comment https://forums.phpfreaks.com/topic/251250-how-to-get-the-default-checked-value-of-a-radio-button-using-php/ Share on other sites More sharing options...
QuickOldCar Posted November 16, 2011 Share Posted November 16, 2011 You don't get the values of the checked POST until you send it in the form. Why not just use the value of $goal for what you need to do until they select something in the form. echo $goal; Quote Link to comment https://forums.phpfreaks.com/topic/251250-how-to-get-the-default-checked-value-of-a-radio-button-using-php/#findComment-1288703 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.