# Validating form by exact words

**URL:** <https://forum.kirupa.com/t/validating-form-by-exact-words/60136>\
**Category:** web dev\
**Created:** [August 6, 2004, 10:34pm UTC](https://forum.kirupa.com/t/validating-form-by-exact-words/60136 "2004-08-06T22:34:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Grinch](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@Adam\_Grinch](https://forum.kirupa.com/u/Adam_Grinch)\
**Post date:** [August 6, 2004, 10:34pm UTC](https://forum.kirupa.com/t/validating-form-by-exact-words/60136/1 "2004-08-06T22:34:42Z")

</div>

Hi guys, I am working on a distance learning system for my school, it will look like this: [http://dsbc.edu/distance/biblical\_intro/biblical\_intro\_1A.htm](http://dsbc.edu/distance/biblical_intro/biblical_intro_1A.htm)  
User will be entering words in blanks as he listen to audio file. I have a problem finding validating script (javascript) that will check entered results.  
The script should trigger when user is done filling blanks and pressed “submit” button. So far I’ve found a couple scripts that seem to be able to do that, but I don’t know how to tune them up for my specific task.

Here is what I’ve got:

f = element  
if ( f.value fails ) {  
alert(“Error …”)  
f.focus()  
return false }

that’s using regular expressions, but maybe there is another way? or how do I get this script to work.

Thank you very much!!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 8, 2004, 1:55am UTC](https://forum.kirupa.com/t/validating-form-by-exact-words/60136/2 "2004-08-08T01:55:56Z")

</div>

ehhhmmmm if I understand correctly then you could try

function FormSubmit(){

f = self.textbox.value;  
if (f == “whatever”)  
{ alert(“Pass”) }  
else  
{ alert(“Fail”); }

}

and then in the form action you declare

form action=“JavaScript: FormSubmit()”

does this help :huh:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 8, 2004, 4:23am UTC](https://forum.kirupa.com/t/validating-form-by-exact-words/60136/3 "2004-08-08T04:23:36Z")

</div>

or may be you can create an array that contains all the correnct values in order like this:

corrects = [“hello”,“yes”,etc];  
//and check all the text fields with one function:

```php

function validate(){

for(i=0;i <corrects.length;++i){ 

if(corrects*!=document.yourForm.elements*.value){ return (false);
break;}
return (true);
document.yourForm.submit();}}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 10, 2004, 9:39pm UTC](https://forum.kirupa.com/t/validating-form-by-exact-words/60136/4 "2004-08-10T21:39:57Z")

</div>

Hi Dulcinea, thanks for your and “RadBell’s” help. How do you create an array? Could you also show me how to assign a function to each text field?  
thanks.
