Connecting Tech Pros Worldwide Forums | Help | Site Map

Javascript form validation script- not defined in Mozilla Firefox

nektir@gmail.com
Guest
 
Posts: n/a
#1: Oct 4 '06
I have an external js file to validate a form and it works in IE and
Opera, but not Mozilla Firefox.

In Mozilla Firefox, the javascript console sasys "SearchForm" is not
defined in the second line

function Valid() {
if ((SearchForm.FirstName.value == "") && (SearchForm.LastName.value
== "") && (SearchForm.Phone.value == "") && (SearchForm.Dept.value ==
"%")) {
alert("Please enter criteria before submitting.");
SearchForm.FirstName.focus();
return false;
}
else if (SearchForm.Company.value == "") {
alert("Please select a company to search by.");
SearchForm.Company.focus();
return false;
}
else
SearchForm.submit();
}

Any ideas?


web.dev
Guest
 
Posts: n/a
#2: Oct 5 '06

re: Javascript form validation script- not defined in Mozilla Firefox



nektir@gmail.com wrote:
Quote:
I have an external js file to validate a form and it works in IE and
Opera, but not Mozilla Firefox.
>
In Mozilla Firefox, the javascript console sasys "SearchForm" is not
defined in the second line
>
function Valid() {
if ((SearchForm.FirstName.value == "") && (SearchForm.LastName.value
== "") && (SearchForm.Phone.value == "") && (SearchForm.Dept.value ==
"%")) {
alert("Please enter criteria before submitting.");
SearchForm.FirstName.focus();
return false;
}
else if (SearchForm.Company.value == "") {
alert("Please select a company to search by.");
SearchForm.Company.focus();
return false;
}
else
SearchForm.submit();
}
>
Any ideas?
Try using the following syntax instead, replace where necessary:

document.forms["SearchForm"].elements["FirstName"].value
document.forms["SearchForm"].elements["LastName"].value
document.forms["SearchForm"].elements["Phone"].value
etc. etc.

McKirahan
Guest
 
Posts: n/a
#3: Oct 5 '06

re: Javascript form validation script- not defined in Mozilla Firefox


<nektir@gmail.comwrote in message
news:1160003637.593444.225060@b28g2000cwb.googlegr oups.com...
Quote:
I have an external js file to validate a form and it works in IE and
Opera, but not Mozilla Firefox.
>
In Mozilla Firefox, the javascript console sasys "SearchForm" is not
defined in the second line
>
function Valid() {
if ((SearchForm.FirstName.value == "") && (SearchForm.LastName.value
== "") && (SearchForm.Phone.value == "") && (SearchForm.Dept.value ==
"%")) {
alert("Please enter criteria before submitting.");
SearchForm.FirstName.focus();
return false;
}
else if (SearchForm.Company.value == "") {
alert("Please select a company to search by.");
SearchForm.Company.focus();
return false;
}
else
SearchForm.submit();
}
>
Any ideas?

Are you declaring it; for example:
var SearchForm = document.forms[0];

Or is it the name of the form; as in:
<form name="SearchForm" ...>

Also, how are you calling your "Valid()" function?


nektir
Guest
 
Posts: n/a
#4: Oct 5 '06

re: Javascript form validation script- not defined in Mozilla Firefox


I'm not declaring as it is the name of the form <form name="SearchForm"
id="SearchForm"..

I'm calling the Valid function like this:

<a href="#" onClick="Valid()"><img src="/images/go.gif" alt="Submit"
width="34" height="19"/></a>

McKirahan wrote:
Quote:
<nektir@gmail.comwrote in message
news:1160003637.593444.225060@b28g2000cwb.googlegr oups.com...
Quote:
I have an external js file to validate a form and it works in IE and
Opera, but not Mozilla Firefox.

In Mozilla Firefox, the javascript console sasys "SearchForm" is not
defined in the second line

function Valid() {
if ((SearchForm.FirstName.value == "") && (SearchForm.LastName.value
== "") && (SearchForm.Phone.value == "") && (SearchForm.Dept.value ==
"%")) {
alert("Please enter criteria before submitting.");
SearchForm.FirstName.focus();
return false;
}
else if (SearchForm.Company.value == "") {
alert("Please select a company to search by.");
SearchForm.Company.focus();
return false;
}
else
SearchForm.submit();
}

Any ideas?
>
>
Are you declaring it; for example:
var SearchForm = document.forms[0];
>
Or is it the name of the form; as in:
<form name="SearchForm" ...>
>
Also, how are you calling your "Valid()" function?
nektir
Guest
 
Posts: n/a
#5: Oct 5 '06

re: Javascript form validation script- not defined in Mozilla Firefox


Changing the syntax fixed it along with changing the call to
Valid(document.Searchform) instead of just Valid()

Thanks for your help guys!

web.dev wrote:
Quote:
nektir@gmail.com wrote:
Quote:
I have an external js file to validate a form and it works in IE and
Opera, but not Mozilla Firefox.

In Mozilla Firefox, the javascript console sasys "SearchForm" is not
defined in the second line

function Valid() {
if ((SearchForm.FirstName.value == "") && (SearchForm.LastName.value
== "") && (SearchForm.Phone.value == "") && (SearchForm.Dept.value ==
"%")) {
alert("Please enter criteria before submitting.");
SearchForm.FirstName.focus();
return false;
}
else if (SearchForm.Company.value == "") {
alert("Please select a company to search by.");
SearchForm.Company.focus();
return false;
}
else
SearchForm.submit();
}

Any ideas?
>
Try using the following syntax instead, replace where necessary:
>
document.forms["SearchForm"].elements["FirstName"].value
document.forms["SearchForm"].elements["LastName"].value
document.forms["SearchForm"].elements["Phone"].value
etc. etc.
McKirahan
Guest
 
Posts: n/a
#6: Oct 5 '06

re: Javascript form validation script- not defined in Mozilla Firefox


"nektir" <nektir@gmail.comwrote in message
news:1160060280.660780.274640@i42g2000cwa.googlegr oups.com...
Quote:
I'm not declaring as it is the name of the form <form name="SearchForm"
id="SearchForm"..
>
I'm calling the Valid function like this:
>
<a href="#" onClick="Valid()"><img src="/images/go.gif" alt="Submit"
width="34" height="19"/></a>
AFAIK, the proper way to reference it is by
"document.SearchForm" not simply "SearchForm".

JavaScript Form Contents
http://www.irt.org/script/form.htm


Q299 When referring to my form using form.field.value
it does not work, why?
http://www.irt.org/script/299.htm

[snip]


McKirahan
Guest
 
Posts: n/a
#7: Oct 5 '06

re: Javascript form validation script- not defined in Mozilla Firefox


"nektir" <nektir@gmail.comwrote in message
news:1160061319.528794.54410@e3g2000cwe.googlegrou ps.com...
Quote:
Changing the syntax fixed it along with changing the call to
Valid(document.Searchform) instead of just Valid()
[snip]
Quote:
Quote:
Quote:
function Valid() {
Did you also change the above to the following?

function Valid(SearchForm) {


RobG
Guest
 
Posts: n/a
#8: Oct 5 '06

re: Javascript form validation script- not defined in Mozilla Firefox



nektir@gmail.com wrote:
Quote:
I have an external js file to validate a form and it works in IE and
Opera, but not Mozilla Firefox.
>
In Mozilla Firefox, the javascript console sasys "SearchForm" is not
defined in the second line
>
function Valid() {
if ((SearchForm.FirstName.value == "") && (SearchForm.LastName.value
[...]
Quote:
>
Any ideas?
It pays to read the FAQ:

<URL: http://www.jibbering.com/faq/#FAQ4_41 >


--
Rob

Dr John Stockton
Guest
 
Posts: n/a
#9: Oct 5 '06

re: Javascript form validation script- not defined in Mozilla Firefox


JRS: In article <1160005825.649585.304360@h48g2000cwc.googlegroups .com>,
dated Wed, 4 Oct 2006 16:50:25 remote, seen in
news:comp.lang.javascript, web.dev <web.dev.cs@gmail.composted :
Quote:
>
>Try using the following syntax instead, replace where necessary:
>
>document.forms["SearchForm"].elements["FirstName"].value
>document.forms["SearchForm"].elements["LastName"].value
>document.forms["SearchForm"].elements["Phone"].value
>etc. etc.

var SFe = document.forms["SearchForm"].elements
SFe["FirstName"].value
SFe["LastName"].value
SFe["Phone"].value

should be both faster and smaller.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Closed Thread