DEVILofDARKNESS Posted September 16, 2009 Share Posted September 16, 2009 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> Quote Link to comment Share on other sites More sharing options...
StefanRSA Posted September 16, 2009 Share Posted September 16, 2009 Use <input type="checkbox" name="services[]" value="Hospital" /> <input type="checkbox" name="services[]" value="GPSurgery" /> Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted September 16, 2009 Author Share Posted September 16, 2009 yes okay and then? if(isset($_POST['services'])){ //what to get the radio button? } Quote Link to comment Share on other sites More sharing options...
prasanthmj Posted September 16, 2009 Share Posted September 16, 2009 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 Quote Link to comment 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.