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

Javascript Quiz - validation help

3
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 1693
iam_clint
1,208 Expert 1GB
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
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 : ...
2
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
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...
6
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...
11
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...
2
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...
5
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:...
4
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...
8
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.