Jump to content

how to get the default checked value of a radio button using php


liomon41

Recommended Posts

   

<?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.

 

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;

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.