Jump to content

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


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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.