Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 76
  • Last Modified:

Require a Radio Button be Selected if a Checkbox is

I am really trying to avoid reverting back to javascript for this but I am having a heck of time in jquery.    I have a checkbox that if checked, I need to require ONE of the radio buttons be selected as well.    This works great if there is only one radio button but not so much if there is more than one...

JQUERY
if ($('input:checkbox[value=658]').is(':checked') && ($("##cepftestid").is(":not(:checked)")) ) {
			 alert('You have selected to purchase a CEFP Exam but you have not indicated the date you wish to attend.');
			 var1 = 0;
		}

Open in new window


HTML
<h2><input type="checkbox" name="itemnumber" value="658" data-cost="600.0000" data-options="#cefpexams" class="itemnumber" > Register for an Exam  ($600.00)</h2>


<div id="cefpexams" style="display:none;">
<input name="cefptestid" type="radio" value="00/00/0000" id="cefptestid"  /> I will take the exam at a proctored location<br />
<input name="cefptestid" type="radio" value="12/30/1899" id="cefptestid"  /></TD><TD> December 30, 2015
</div>

Open in new window

0
digitalwise
Asked:
digitalwise
  • 3
  • 2
1 Solution
 
Rainer JeschorCommented:
Hi,
there are some typos in your code (e.g. wrong radiobutton ID selector):
if ($('input:checkbox[value=658]').is(':checked') && !($("#cefptestid").is(":checked")) ) {
			 alert('You have selected to purchase a CEFP Exam but you have not indicated the date you wish to attend.');
			 var1 = 0;
		}

Open in new window


And here a sample:
http://jsfiddle.net/EE_RainerJ/yjqxbyj9/

HTH
Rainer
0
 
digitalwiseAuthor Commented:
Thank you!   I need 5 minutes to breath so I can actually look over JQUERY instead of just finding what I need!
0
 
Chris StanyonCommented:
Ooooh. You accepted an answer before I had a chance to comment. Rainer's solution won't. Tick the box and select the second radio button, and you'll still get the error!

Your inputs are using the same IDs, and as I've said before, they need to be unique!!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
digitalwiseAuthor Commented:
Ah!   And I only tested it for the first one and it worked.    So if they are unique, how the heck do I make sure ONE of them is selected?    Do I need to reopen this or something??   Ughhh!
0
 
Rainer JeschorCommented:
Hi,
Chris is right (I thought I tested all options). Nevertheless, another (correct) selector would be:
$('input:radio[name="cefptestid"]')

Open in new window


I have updated the jsFiddle from above as well:
http://jsfiddle.net/EE_RainerJ/yjqxbyj9/

HTH
Rainer
0
 
digitalwiseAuthor Commented:
Thanks guys!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now