validate text box-clause test

Part of the code are below. I need to continue it so that when you click the check results the score is displayed and the percentage results also.


<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>feedback form</TITLE>
<script LANGUAGE="JavaScript">

 
 function checkresults()
 {
 if (document.form1.clause1.value=="quickly")
       {
       return true;
       }
 if (document.form1.street.value=="nothing")
       {
       return true;
       }
 if (document.form1.street.value=="assist")
       {
       return true;
       }
 if (document.form1.street.value=="coaching")
       {
       return true;
       }
 if (document.form1.street.value=="skill")
       {
       return true;
       }
       return false;
 }

function maskKeyPress(objEvent)
      {
        var iKeyCode;        
        iKeyCode = objEvent.keyCode;                  
        if(iKeyCode>=97 && iKeyCode<=122) return true;
        return false;
      }

</script>

<LINK HREF=format.css TYPE=text/css REL=stylesheet >
<STYLE>
H2 {text-align:left;
    font-size:15pt;
    font-weight:bold;}
H5 {font-family:Comic sans MS;
    font-size:13pt;}
H4 {color:red;}  
</STYLE>
</HEAD>

<BODY>

<FORM name=form1 >



<H4>Please do the clause test using the pool of words below</H4>


<H5>How <INPUT type=text NAME=clause1 size=10 onkeypress="return maskKeyPress(event)"> can you find out what is unusual about this paragraph? It looks so <br>
ordinary that you would think that nothing was wrong with it at all and, in fact,<INPUT type=text NAME=clause2 size=10 onkeypress="return maskKeyPress(event)"> <br>
is. But it is unusual. Why? If you study it and think about it you may find out, but I am not <br>
going to<INPUT type=text NAME=clause3 size=10 onkeypress="return maskKeyPress(event)"> you in any way. You must do it without <INPUT type=text NAME=clause4 size=10 onkeypress="return maskKeyPress(event)">.No doubt, if you<br>
work at it for long, you will finally find a solution. Who knows? Go to work and try your <br>
<INPUT type=text NAME=clause5 size=10 onkeypress="return maskKeyPress(event)">. Most of you will find it in about half an hour.<br></H5>

<H4> Pool: quickly, coaching, skill, nothing, assit </H4>


<P><input TYPE="button" value="Check Results" onClick=validateresults()> <INPUT type=reset> </P>
</FORM>



</BODY>
</HTML>
sharfaaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
WHat is the mask event supposed to be good for?

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>feedback form</TITLE>
<script LANGUAGE="JavaScript">
answers = new Array(
"quickly",
"nothing",
"assist",
"coaching",
"skill"
)

 
function validateresults(theForm) {
  good=0;
  bad=0;
  for (i=0;i<answers.length;i++) {
    answer = theForm.elements["clause"+(i+1)].value.toLowerCase();
    if (answer != "") {
      if (answer == answers[i]) good ++
      else bad++
    }
  }
  if (bad>0) {
    alert('Good: '+good+'\nErrors:'+ bad)
    return false
  }
}

function maskKeyPress(objEvent)  {

  var iKeyCode;      
  iKeyCode = objEvent.keyCode;  
             
  if(iKeyCode>=97 && iKeyCode<=122) return true;
  return false;
}

</script>

<LINK HREF=format.css TYPE=text/css REL=stylesheet >
<STYLE>
H2 {text-align:left;
    font-size:15pt;
    font-weight:bold;}
H5 {font-family:Comic sans MS;
    font-size:13pt;}
H4 {color:red;}  
</STYLE>
</HEAD>

<BODY>

<FORM name=form1 >



<H4>Please do the clause test using the pool of words below</H4>


<H5>How <INPUT type=text NAME=clause1 size=10 onkeypress="return maskKeyPress(event)"> can you find out what is unusual about this paragraph? It looks so <br>
ordinary that you would think that nothing was wrong with it at all and, in fact,<INPUT type=text NAME=clause2 size=10 onkeypress="return maskKeyPress(event)"> <br>
is. But it is unusual. Why? If you study it and think about it you may find out, but I am not <br>
going to<INPUT type=text NAME=clause3 size=10 onkeypress="return maskKeyPress(event)"> you in any way. You must do it without <INPUT type=text NAME=clause4 size=10 onkeypress="return maskKeyPress(event)">.No doubt, if you<br>
work at it for long, you will finally find a solution. Who knows? Go to work and try your <br>
<INPUT type=text NAME=clause5 size=10 onkeypress="return maskKeyPress(event)">. Most of you will find it in about half an hour.<br></H5>

<H4> Pool: quickly, coaching, skill, nothing, assit </H4>


<P><input TYPE="button" value="Check Results" onClick="validateresults(this.form)"> <INPUT type=reset> </P>
</FORM>



</BODY>
</HTML>


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michel PlungjanIT ExpertCommented:
Sorry, you want to change

  if (bad>0) {
    alert('Good: '+good+'\nErrors:'+ bad)
    return false
  }
}

to

  alert('Good: '+good+'\nErrors:'+ bad)
  return bad==0
}


and possibly

<form...
<input TYPE="button" value="Check Results" onClick="validateresults(this.form)">
to

<form... onSubmit="return validateresults(this)
<input TYPE="button" value="Check Results" onClick="validateresults(this.form)">
<input TYPE="submit" value="Send Results">

0
sharfaaAuthor Commented:
Well thank you very much .I have added the percentage and with the mask event there is no need to put the toLowerCase() and any other character except lowercase letters that  can be entered
Here is the corrected code.

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>feedback form</TITLE>
<script LANGUAGE="JavaScript">
answers = new Array(
"quickly",
"nothing",
"assist",
"coaching",
"skill"
)

 
function validateresults(theForm) {
  good=0;
  bad=0;
  for (i=0;i<answers.length;i++) {
    answer = theForm.elements["clause"+(i+1)].value;
    if (answer != "") {
      if (answer == answers[i]) good ++
      else bad++
    }
  }
  alert('No. of Good answers out of 5 = '+good+'\nYour Percentage= '+((good/5)*100)+'  %')
  return bad==0
}



function maskKeyPress(objEvent)  {

  var iKeyCode;      
  iKeyCode = objEvent.keyCode;  
             
  if(iKeyCode>=97 && iKeyCode<=122) return true;
  return false;
}

</script>

<LINK HREF=format.css TYPE=text/css REL=stylesheet >
<STYLE>
H2 {text-align:left;
    font-size:15pt;
    font-weight:bold;}
H5 {font-family:Comic sans MS;
    font-size:13pt;}
H4 {color:red;}  
</STYLE>
</HEAD>

<BODY>

<FORM name=form1 onSubmit="return validateresults(this)" >





<H4>Please do the clause test using the pool of words below</H4>
<H5>CAUTION: You need to fill all text boxes before you click on check results<BR>
and make sure caps lock is not on </H5>


<H5>How <INPUT type=text NAME=clause1 size=10 onkeypress="return maskKeyPress(event)"> can you find out what is unusual about this paragraph? It looks so <br>
ordinary that you would think that nothing was wrong with it at all and, in fact,<INPUT type=text NAME=clause2 size=10 onkeypress="return maskKeyPress(event)"> <br>
is. But it is unusual. Why? If you study it and think about it you may find out, but I am not <br>
going to<INPUT type=text NAME=clause3 size=10 onkeypress="return maskKeyPress(event)"> you in any way. You must do it without <INPUT type=text NAME=clause4 size=10 onkeypress="return maskKeyPress(event)">.No doubt, if you<br>
work at it for long, you will finally find a solution. Who knows? Go to work and try your <br>
<INPUT type=text NAME=clause5 size=10 onkeypress="return maskKeyPress(event)">. Most of you will find it in about half an hour.<br></H5>

<H4> Pool: quickly, coaching, skill, nothing, assit </H4>


<P><input TYPE="button" value="Check Results" onClick="validateresults(this.form)">
<input TYPE=reset>
</P>
</FORM>



</BODY>
</HTML>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.