Jump to content

[SOLVED] radio buttons based on checkboxes


DEVILofDARKNESS

Recommended Posts

I have a form with checkboxes and radio buttons,

How can I get the value of the radio buttons based on the checkboxes?

 

<td><input type="checkbox" name="services" value="GPSurgery" /></td>
    <td> </td>
    <td><div align="center"><input type="radio" name="GPSurgery" value="VeryGood" /></div></td>
    <td><div align="center"><input type="radio" name="GPSurgery" value="Good" /></div></td>
    <td><div align="center"><input type="radio" name="GPSurgery" value="Neither" /></div></td>
    <td><div align="center"><input type="radio" name="GPSurgery" value="Poor" /></div></td>
    <td><div align="center"><input type="radio" name="GPSurgery" value="VeryPoor" /></div></td>
  </tr>
  <tr>
    <td>Hospital</td>
    <td><input type="checkbox" name="services" value="Hospital" /></td>
    <td> </td>
    <td><div align="center"><input type="radio" name="Hospital" value="VeryGood" /></div></td>
    <td><div align="center"><input type="radio" name="Hospital" value="Good" /></div></td>
    <td><div align="center"><input type="radio" name="Hospital" value="Neither" /></div></td>
    <td><div align="center"><input type="radio" name="Hospital" value="Poor" /></div></td>
    <td><div align="center"><input type="radio" name="Hospital" value="VeryPoor" /></div></td>
  </tr>

function IsCheckSelected($val)
{
$services = $_POST['services'];

$N = count($services);
for($i=0; $i<$N;$i++)
{
  if($val == $services[$i])
  {
    return true;
  }
}
return false;
} 

then

if(IsCheckSelected("GPSurgery"))
{

} 

 

more examples here:

Handling checkbox in a PHP form

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.