473,395 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Checkbox field validating radio button....?

rush it
18
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 2225
Dormilich
8,658 Expert Mod 8TB
how do you (try to) prevent the form from submitting?
Oct 11 '11 #2
rush it
18
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 Expert Mod 8TB
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
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 Expert Mod 8TB
all you need to do is stopping the button from executing its default action. as of IE 9 this is done via Event.preventDefault() and if I remember right previous versions of IE use event.returnValue = false;
Oct 13 '11 #6
rush it
18
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 Expert Mod 8TB
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
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
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...
3
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)...
2
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...
2
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...
1
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
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
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...
0
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" %> ...
4
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. ...
2
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.