473,398 Members | 2,404 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,398 software developers and data experts.

Javascript validation of dependent form fields

rush it
18
First off, let me say I'm pretty new to web design and programming in general. Call it a career change. But I love it. :)

I'm building an online form for users to apply for a discount on park sports for their child. In this form, I need to have one of the fields validate another. Field_1, a radio button, is in one section of the form but I can't validate it because it may not apply to all users. Field_2, a checkbox, is in the section below it, related to Field_1, and does require validation.

Field_1 is the 'Free Lunch' selection in an area that asks users which lunch program their child is in at school. (A criterion for receiving the park sports discount.)

Field_2 asks the user to agree that they understand that if their child is enrolled in the free lunch, they only pay 25% of the park sports fee. (I hope this is all making sense. I'm trying to break it down into sections.)

I would like to have the '25%' checkbox, if selected, prompt the user to check the 'Free Lunch' radio button. I know this can be done for matching values, but I just want to check for field selection.

This is what I have for a simple field.

Expand|Select|Wrap|Line Numbers
  1. var s=document.forms["form2"]["name"].value
  2.     if (s==null || s=="")
  3.   {
  4.   alert("Please enter Name");
  5.   return false;
  6.   }
  7.  

This works fine for the simple fields. I've been researching how to have Field_2 validate Field_1, and quite frankly, I'm very confused as to which way I should go.

This is something I came across, but it doesn't work, I think, because this function calls for names, not values, and I'm working with radio buttons and checkboxes. It simply doesn't not validate the field at all.

Expand|Select|Wrap|Line Numbers
  1. var tos = new Ext.form.checkbox({ 
  2.       name: 'free', 
  3.       fieldLabel: 'free' 
  4.      }); 
  5.   var lunch_program = new Ext.form.radio({ 
  6.       name: 'Free Lunch', 
  7.       fieldLabel: 'Free Lunch' 
  8.        validator: function(checked){ 
  9.     if(free.getValue() != checked) { 
  10.         return 'Please select 'Free Lunch Participant' under 'Does your child particpate in the school's free and reduced program?' ; 
  11.       } else {
  12.      return true; 
  13.     } 
  14.  
I'd appreciate any guidance anyone can suggest.
Oct 4 '11 #1
5 2011
acoder
16,027 Expert Mod 8TB
Are you currently using the Ext JS library or did you use it because you found this code?
Oct 13 '11 #2
rush it
18
I was already using javascript when I found this code.
Oct 14 '11 #3
Rabbit
12,516 Expert Mod 8TB
He's asking if you are using the EXT library on purpose. Because you can't just start using it out of nowhere.
Oct 14 '11 #4
rush it
18
Well, as I said in my original post, I'm new to web design and pretty new to programming. I've not even heard of the Ext library before. I see the Ext in the code now. This code is just an example. If there's another way to do this in just javascript, IF that makes sense, that would be great. Right now, I'm hung up on the syntax. Thanks.
Oct 17 '11 #5
gits
5,390 Expert Mod 4TB
to simplyfy that all - please post an example of your code with a description of the requirement, and don't post snippets that you don't use. so in short words: what exactly do you have so far?

regards,
gits
Oct 18 '11 #6

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

Similar topics

5
by: Batezz | last post by:
I have created a form (below) How do I stop it redirecting to another page (productsearchresults.php) when form is submitted if both the fields are blank? Any help appreciated. Batezz
3
by: NotGiven | last post by:
I have a web form with several fields. If I copy & paste from a RTF document into a field, the javascript validation and field length are bypassed and cause the form to fail. Any ideas?
2
by: Mike N. | last post by:
I am looking to use an HTML checkbox feature as a trigger to shade/unshade a multiple select field in an HTML form. For instance: there are four options in the multiple select field and one outside...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
4
by: TJS | last post by:
how do I get "onSubmit" to work in .net ? <Form id="Form1" name="Form1" method="post" onSubmit="return validateStandard(this, 'error');" runat="server">
2
by: Jon | last post by:
All, I'm currently working with a PHP-based CMS application, and am begining to put the finishing touches on it via Javascript validation. Currently, I'm using fairly standard methods of...
5
by: Advo | last post by:
Basically, im redesigning a form page on our website. Currently the user submits the form, it does a few javascript checks and either submits to the "processstuff.php" page, or gives the user a...
1
by: karen987 | last post by:
I have a comment form, on a news website, ASP page, which users fill in and it adds comments to a news article. The reader clicks on a headline and the comments open up in a new window. It already...
1
by: shrin | last post by:
Hi all, I want to use asp.net validator and javascript validation function on a single form for different fields. also I want to execute some code on button click after the validation is completed....
3
by: dirk | last post by:
Hi, Being new coding in phpI have a question concerning server side form validation. In a php script I check if a form is correctly filled in. Now I want that the page containing the forms...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
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...

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.