473,698 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript Quiz - validation help

3 New Member
Hi,
I've put together a little quiz using javascript. It doesn't actually keep score, it let's you keep answering the same question until you get it right. Most of the questions use multiple choice radio buttons and I have them working fine. One of the questions requires the user to enter a letter into 5 text input fields. The user has to enter A,B,C,D or E into each field. I wanted it to allow upper or lower case, so I used regular expressions to set a range of acceptable answers for each field. I can get it to work on one field but the way the function works, if they get the first answer right, it returns true and thinks it is finished and then takes the user to the next page without validating the other 4 fields. Here's the script:
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. <!--
  3.  
  4. g1 = /[eE]/
  5. g2 = /[dD]/
  6. g3 = /[aA]/
  7. g4 = /[cC]/
  8. g5 = /[bB]/
  9.  
  10. function checkanswer() {
  11.  
  12. {
  13. if (g1.test(question4.goal1.value)) {
  14.    return true
  15.    }
  16.    alert ("That is incorrect. Please try again.")
  17.    question4.goal1.focus()
  18.    question4.goal1.select()
  19.    return false
  20.    }
This works, but only for the first field. I know why it is passing up the other fields once the first field is correct, but I don't know another way to write this script so that it goes to each of the other fields before returning true. Can anyone help? Thanks.
Apr 12 '07 #1
1 1726
iam_clint
1,208 Recognized Expert Top Contributor
well you need it to check all of them at once or one at a time before returning anything example

strictly example wont work
Expand|Select|Wrap|Line Numbers
  1. function check4fields() {
  2. if (question1.value && question2.value && question3.value && question4.value) {
  3. return true;
  4. } else {
  5. return false;
  6. }
  7. }
  8.  
Apr 12 '07 #2

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

Similar topics

4
9211
by: C. David Rossen | last post by:
Hello: I found a script for a simple multiple choice quiz that I would like to tailor to a quiz that I want to post on a website. The quiz I want to use can be found at : http://mtl.math.uiuc.edu/users/C2Schult/quiz2.html Here is my problem. I want to be able to use answers with more than one word or number which requires spaces. When I tried doing that, it did not
2
2644
by: Sketcher | last post by:
Hi, I am trying to create a quiz, Code is as follows: <html> <head> <title>Quiz</title> </head> <BODY> <Center><TABLE cellSpacing=3 cellPadding=0 border=0>
17
2274
by: rgoya | last post by:
Peace be with you! About a year ago, I created a JavaScript which turns any web site into an online anti-war protest: http://www.geocities.com/rgoya/javascript/PROTEST.HTM I have recently revamped the anti-war quotes quiz: http://www.geocities.com/rgoya/javascript/PROTCODE.HTM#usaquiz Please feel free to
6
1598
by: Vandana Rola | last post by:
Hello Everyone, I posted this question earlier under creating Multiple choice quiz. Is it possible to ignore something using javascript. What I am trying to do is creating a multiple answer quiz. I have five choices out of which user are supposed to choose 3 best choices. The user should get feedback on the choices they make. I have been able to provide the feedback for all the choices but my problem is I am also getting the feedback on...
11
3316
by: admin | last post by:
Hi all, First time poster here... I'm a webmaster and I'd like to add a simple script to my website which will allow users to fill in a brief multiple choice questionaire, and then provide a 'thoughful' suggestion based on their answers. In terms of the logic involved with the actual script: I've mulled it over and thoroughly broken my brain, trying to devise a complicated 'scoring system' (with different answers giving different...
2
3428
by: kenny | last post by:
I'm making a quiz to be posted on the internet. but I'm facing difficulties in finding a simple timer for the quiz (unlimited timing) which will keep on running regardless to the change of the page throughout the quiz. And well how to display the result of the quiz and te grade of the person who has taken the quiz....
5
1498
by: Steve | last post by:
I need to make an HTML page that has multiple choice quiz questions that pull from an XML doc. I have been looking at various online examples of how to do this, mainly this one: http://www.quirksmode.org/dom/importxml.html , but I can't get this damn thing working. Any help is appreciated, but if you write out the html/javascript code you'll be my hero. The example XML doc: <?xml version="1.0" ?> <quiz>
4
68228
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer must be embedded somewhere in the source code, and I would like to know if anyone knows where to find the correct answer. I would greatly appreciate it!! Thanks!!
8
6420
by: danjoplin | last post by:
I've only recently started javascript and I'm a java programmer so I'm sure I've done something obvious that I can't see. Basically this goes with an html document which has a number of questions on it, when the form is submitted it gets run through the getScore method. The questions are named q1, q2 etc.. If anyone with experience could help me it would be much appreciated. Thanks, Dan var a = new Array(form.q1.value, form.q2.value,...
0
8601
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9021
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7716
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4365
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3043
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
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.