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> Link to comment https://forums.phpfreaks.com/topic/174423-solved-radio-buttons-based-on-checkboxes/ 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" /> Link to comment https://forums.phpfreaks.com/topic/174423-solved-radio-buttons-based-on-checkboxes/#findComment-919359 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? } Link to comment https://forums.phpfreaks.com/topic/174423-solved-radio-buttons-based-on-checkboxes/#findComment-919363 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 Link to comment https://forums.phpfreaks.com/topic/174423-solved-radio-buttons-based-on-checkboxes/#findComment-919416 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.