473,569 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checkbox field validating radio button....?

rush it
18 New Member
Is it possible to have a checkbox validate a radio button? I have two radio buttons (Free Lunch and Reduced Lunch). If the user chooses either of these, the checkbox below (Please agree to the release of school information about your lunch program...) must be checked. This checkbox ONLY needs to be selected IF one of the radio buttons is selected. So far I'm trying to do this in javascript.

Here's what I have now that is not working. When testing the form, I'm selecting a radio button, and not selecting the checkbox and the form submits anyway.

Expand|Select|Wrap|Line Numbers
  1.  
  2. function validateLunchSelection()
  3.  
  4.  if((form2.lunch_program[0].checked==true || form2.lunch_program[1].checked==true) && (form2.lunch_auth.checked==false))
  5. {
  6. alert("Please agree to release of lunch information from your school");
  7. form2.lunch_auth.focus();
  8. return false;
  9. }
  10.  
  11.  
Oct 11 '11 #1
8 2228
Dormilich
8,658 Recognized Expert Moderator Expert
how do you (try to) prevent the form from submitting?
Oct 11 '11 #2
rush it
18 New Member
Sorry, but that's what I'm having problems with. I'm using javascript validation for the other fields, but can't figure out how to associate these two fields. Guess I'm not sure what you're asking.
Oct 12 '11 #3
Dormilich
8,658 Recognized Expert Moderator Expert
in general there are three major ways of submit and validate a form
- preventing the submit action of the form itself (if validation failed)
- preventing the submit button from submitting (if validation failed)
- not using a submit button (but a click button) and submit (or not) the form via JavaScript

there are various ways to implement each way, depending in the version of IE that has to be supported
Oct 13 '11 #4
rush it
18 New Member
I'm preventing submission by the submit button, the second item you listed (when validation fails). We're concerned with supporting IE 7, 8, and 9. Thanks for your time.
Oct 13 '11 #5
Dormilich
8,658 Recognized Expert Moderator Expert
all you need to do is stopping the button from executing its default action. as of IE 9 this is done via Event.preventDe fault() and if I remember right previous versions of IE use event.returnVal ue = false;
Oct 13 '11 #6
rush it
18 New Member
Thanks, that will keep the from from submitting when it shouldn't, but do you have experience with my first question about a checkbox field validating a radio button?
Oct 13 '11 #7
Dormilich
8,658 Recognized Expert Moderator Expert
on click on either radio button trigger a function that
- tests if either redio button is checked
- tests if the checkbox is checked or set the checkbox to checked
Oct 14 '11 #8
rush it
18 New Member
I don't need to validate the radio buttons and checkbox separately, but together. If either radio button is selected, the checkbox MUST be selected. All three deal with two possible answers to a question (radio buttons), then the checkbox is a legal release of information. If this can't be done in javascript, then I'll validate them a more standard way. I'm not even sure if it CAN be done. The syntax I've tried isn't working. Thanks.
Oct 14 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4102
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT the NO radio button, once I do that it will not work. Any help would be greatly appreciated. Mitch
3
2347
by: ewitkop90 | last post by:
Here is my code: <SCRIPT> function transportchange(transport) { if (framenewinstall.Helpdesk.checked) framenewinstall.Helpdesk.checked=false; if (framenewinstall.CircuitNumber.checked) framenewinstall.CircuitNumber.checked=false; switch (transport) { case 0: Helpdesk.innerText="No Info Needed";
2
7968
by: Neo | last post by:
I put a similar post for CheckBoxes, but i want to use a Radio button & not a CheckBox I have a field named "Male" & this is of SQL BIT data type (SQL Server). How can i bind this field to a check box? I noticed that this field can be NULL, 0 or 1. But i'm having trouble binding this field to my check box. i get an error when i try the...
2
3468
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button "No", he should not have the option of clicking on any of the six checkboxes. See Code attached. Thank you so much in advance for your help as I...
1
1830
by: puja | last post by:
hi all, I have a form which has checkbox list which has items as below 1) Input 1 2) Input 2 3) Input 3 4) Input 4 5) Input 5
11
2063
by: tracy.cooperjr | last post by:
I have four checkboxes. I want only one of them to be checked at a time. Any ideas?
6
5716
by: Rob | last post by:
Hi all, I would like to have a textarea control on my web page that is complete with terms and conditions, in addition, I would like a radio button beneath this to indicate the acceptance of these terms and conditions. The part which I am struggling to find information online about is how to only activate the radio button (ie, prior to...
0
1577
by: dancer | last post by:
Can somebody tell me why my RequiredFieldValidator works for the TEXT BOX, (location) but does NOT work for the RADIO BUTTON (EmpTrain)? <%@ Page Language="VB" ClientTarget="downlevel" %> <%@ Import Namespace="System.Web.Mail" %> <script language="VB" runat="server">
4
3017
by: pureadrenaline | last post by:
Hey Guys, Please could anyone help me out with the following form I need to create a validation on the email field only if the user checked the radio button named Email. Thanks in advance. <form action="" method="get"> <div align="center"> <table border="0" cellspacing="0" cellpadding="0">
2
5997
by: makunta | last post by:
Hi all, First here is the website of what I am trying to do: http://www.exmhosting.com/ Locate the login form on the top-right of the page. What I need to do is allow the user to sign into different sections of the website according to the radio button choice at login. If the user chooses Webmail then they input their email address and...
0
7614
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.