We help IT Professionals succeed at work.

Comma Separated Check boxes need to only select one

509 Views
Last Modified: 2013-11-19
Hi, I have 4  text fileds in a form that are populated with coma seperated checkboxes from a mySqL  using database, and PHP the 4 fileds display all the checkboxes just fine, but i need to add a script that would only allow 1 checkbox to be selected out of all of them.  Can anyone help with javascript for this.

here is the code being used for the text fields.

<td width="216" valign="top" bgcolor="#FFFFFF" class="body"><table width="100%" border="0" cellpadding="2" cellspacing="0">
                          <tr class="body">
                            <td height="32" valign="middle" bgcolor="#EFEFEF" class="body"><span class="bodybold">FAA Flight Training<br>
                              Type Rating Initial </span></td>
                          </tr>
                          <tr class="body">
                            <td valign="top" class="boxlineBTM"><input name="choice_ffttri" class="body" id="choice_ffttri" size="16" wdg:recordset="faaTraining" wdg:subtype="CommaCheckboxes" wdg:type="widget" wdg:displayfield="faa_init_name" wdg:valuefield="faa_init_name" wdg:groupby="1"></td>
                          </tr>
                         
                          <tr>
                            <td bgcolor="#FFFFFF">&nbsp;</td>
                          </tr>
                          <tr class="body">
                            <td height="32" colspan="-2" valign="middle" bgcolor="#EFEFEF" class="body"><span class="bodybold">Type Rating<br>
                              Prior Experience</span></td>
                          </tr>
                          <tr class="body">
                            <td colspan="-2" valign="top" class="boxlineBTM"><input name="choice_trpe" class="body" id="choice_trpe" size="16" wdg:recordset="PriorExp" wdg:subtype="CommaCheckboxes" wdg:type="widget" wdg:displayfield="type_prior_name" wdg:valuefield="type_prior_name" wdg:groupby="1"></td>
                          </tr>
                         
                        </table></td>
                        <td width="244" colspan="-2" valign="top" class="body"><table width="101%" border="0" cellpadding="2" cellspacing="0" class="boxlineBTM">
                          <tr class="body">
                            <td height="32" colspan="-2" valign="middle" bgcolor="#EFEFEF" class="body"><span class="bodybold">Recurrent<br>
Training</span></td>
                          </tr>
                          <tr class="body">
                            <td colspan="-2" valign="top" class="boxlineBTM"><input name="choice_rt" class="body" id="choice_rt" size="16" wdg:recordset="Recurrent" wdg:subtype="CommaCheckboxes" wdg:type="widget" wdg:displayfield="recurrent_name" wdg:valuefield="recurrent_name" wdg:groupby="1"></td>
                          </tr>
                         
                          <tr>
                            <td bgcolor="#FFFFFF">&nbsp;</td>
                          </tr>
                          <tr>
                            <td bgcolor="#EFEFEF"><strong class="bodybold">Other Courses</strong></td>
                          </tr>
                          <tr>
                            <td><input name="choice_oc" class="body" id="choice_oc" wdg:recordset="othercourse" wdg:subtype="CommaCheckboxes" wdg:type="widget" wdg:displayfield="other_name" wdg:valuefield="other_name" wdg:groupby="1"></td>
                          </tr>
                        </table></td>
Comment
Watch Question

Joe WuDeveloper | Solutions Architect | CTO
CERTIFIED EXPERT

Commented:
Please correct me if I am wrong, but you are wanting to allow only 1 selection out of the 4 choices? If so, why not just use radio buttons?

Apologies in advance if I misunderstood your question.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks rlbalan,
Im using adobe Developer Toolbox to generate the comma separated checkboxes and i don't have the option for radio btns. The code you sent looks like it will work but how can i apply this function to the 4 different text fields acting as containers for the checkboxes.  thanks

Commented:
Couple of options,
if you want this alert to trigger when the chekbos is selected, you need to add "onChange" event to each of these checkboxes. I havent done actionscripts, but I assume there is some way to add the onChange event to these checkboxes
onChange="javascript:validateSelect()"

Else, u can call this function when you click the submit button of that page.
onClick="javascript:validateSelect()"

Author

Commented:
thanks, it would be great if when i selected one of the dynamci check boxes it de-selects the other if their is another selected. would eleiminate an error.
if you only ever want one selected then you should be using radio buttons instead of checkboxes

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.