Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textarea -> text validation! :-)

Status
Not open for further replies.

Bramvg

IS-IT--Management
Jan 16, 2001
135
BE
Hi,

Description:
----------------------
In my application [testing] users listen to an audio file and they need to typ the text they hear into a textarea field.

In my database, I have the final, correct text!

Problem:
----------------------
How can I compare these two texts?
But in order to make it more complex [;-)] I need to be able to count the number of the mistakes, because everytime they make a mistake, a counter will be increased by 1.

All the specials signs, like ?/. must be replaced as well, also white spaces. But that isn't much of a problem, GunJack was so good to help me out on that one ;-)

Thank you word:
------------------------
;-) Many thanks in advance!


Bram




 
My suggestion is to put both texts(from DB and Input) into array. You can do this by read the text as string then strip and keep each character in array.
Then loop and compare each array index one by one.
I don't know this is the best solution but I think it's a good way to start.


 
Hi,
Here is another option. If you would like to make it a little more dynamic. This way you can let them know the answer was wrong before they submit. Also it keeps track of wrong answers, filtering out any time they click in and out of a field without typing.

This assumes that you have a Query called "MyQuestionsAndAnswers"
with Fields Question and Answer both as text values.

It outputs a list of Questions from the Question field, then monitors the activity in ths form and everytime something is typed it checks to see if it matches the Answer field for that Question. It Also increments a counter when the answer is wrong and makes an alert box. I put the counter in a Text field but you would probably want to use a hidden field.

<script language=&quot;javascript&quot;>
<CFOUTPUT Query=&quot;MyQuestionsAndAnswers&quot;>


function validQ#currentrow#(form)
{
Answer = document.TestThis.Question#currentrow#.value;
if (Answer!=&quot;&quot;)
{
if (Answer!=&quot;#Answer#&quot;)
{
(document.TestThis.WrongAnswerCount#currentrow#.value++);
alert(&quot;Wrong Answer...&quot;);
}

}

}
</CFOUTPUT>
</script>
<html>
<body>
This is of course assuming that the correct answer is held in a field called &quot;Answer&quot;.

Then in your form do this:

<FORM name=&quot;TestThis&quot; Action=&quot;score.cfm&quot; method=&quot;post&quot;>
<CFOUTPUT Query=&quot;MyQuestionsAndAnswers&quot;>
Question #currentrow#: -- #Question#  
<input type=&quot;text&quot;
id=Question#currentrow#
name=Question#currentrow#
OnBlur=&quot;validQ#currentrow#(this.form)&quot; size=20>

<input type=&quot;text&quot; name=&quot;WrongAnswerCount#currentrow#&quot; size=5> <br>

</CFOUTPUT>
<input type=&quot;submit&quot; value=&quot;Send&quot;>
</form>
</body>
</html>

I tried it out and it works fine. Let me know if you have any problems adapting it to your database setup.

Have fun...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top