Jump to content

PHP radio buttons - 2 groups - need to clear both on select


Recommended Posts

Hi, newbie here (to complicated php)

 

Trying to deselect 2 different radio button groups when a single third one is clicked;  Here is the code I have:

 

<?php radio($data, 'educationsessions', 'Infrastructure Asset Management Simplified'); ?><br />
<?php radio($data, 'educationsessions', 'Create, attract and maintain a strong and thriving business community'); ?><br />
<?php radio($data, 'educationsessions', 'Balancing the Municipal Books'); ?><br />
<?php radio($data, 'educationsessions', 'Managing to Have Fun:  Laughing Matters!'); ?><br />
<?php radio($data, 'educationsessions', 'The AUMA & AMSC Business Services'); ?><br />
<?php radio($data, 'educationsessions', 'LGAA: The Brand: Harmonizing Identify and Destiny in Communities'); ?><br />
<?php radio($data, 'educationsessions', 'Council Obligations'); ?><br />
 
 
<?php radio($data, 'educationsessions2', 'Connecting with Your Community', 'Connecting with Your Community: Leveraging New Media'); ?><br />
<?php radio($data, 'educationsessions2', 'Participating in Canada\'s Political Landscape'); ?><br />
<?php radio($data, 'educationsessions2', 'Building Consensus, Achieving Results'); ?><br />
<?php radio($data, 'educationsessions2', 'Advancing Sustainability in Your Community'); ?><br />
<?php radio($data, 'educationsessions2', 'Addressing the Affordable Housing Challenge'); ?><br />
<?php radio($data, 'educationsessions2', 'Meeting Transportation Needs in Your Community'); ?><br />
 
<br>
<strong>Special Extended Session 1:45 pm 4:00pm</strong><br>
<?php radio($data, 'educationsessions3', 'The Future of Municipal Government:  Inspiring the Evolution'); ?>
 
AND the function
 
function radio($data, $name, $value, $value2 = false, $attrs){
 
$curval = $data[$name];
$h = "";
if($attrs && count($attrs)){
foreach($attrs as $key => $attr){
$h .="".$key."=\"".$attr."\" ";
}
}
 
echo "<label><input ".$h." ".($curval==$value ? 'checked':'')." type='radio' name='".$name."' value='".$value."'> ".($value2 ? $value2 : $value)."</label>";
}
 
 
any help would be awesome
 

Hi Sleepy,

 

Actually they can select 1 from the first group and one from the second group. If they choose the third then I need to clear the first two.

first group is a morning session 2nd is afternoon 3rd is full day.

Then

1. Write some PHP (where you process the form) that validates them having only selected ones from the first two or one from the third.

2. Write some Javascript that will automatically deselect all from the first two groups if any from the third group is selected; also deselect all from the third if any in the first two are selected.

 

Moved from Coding Help.

 

Are you using a Javascript framework? Which?

 

[edit] And what does the outputted HTML look like?

Edited by requinix
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.