469,287 Members | 2,689 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,287 developers. It's quick & easy.

Javascript form validation script- not defined in Mozilla Firefox

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?

Oct 4 '06 #1
8 12539

ne****@gmail.com wrote:
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.

Oct 4 '06 #2
<ne****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
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?
Oct 5 '06 #3
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:
<ne****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
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?
Oct 5 '06 #4
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:
ne****@gmail.com wrote:
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.
Oct 5 '06 #5
"nektir" <ne****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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]
Oct 5 '06 #6
"nektir" <ne****@gmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
Changing the syntax fixed it along with changing the call to
Valid(document.Searchform) instead of just Valid()
[snip]
function Valid() {
Did you also change the above to the following?

function Valid(SearchForm) {
Oct 5 '06 #7

ne****@gmail.com wrote:
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
[...]
>
Any ideas?
It pays to read the FAQ:

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

Oct 5 '06 #8
JRS: In article <11**********************@h48g2000cwc.googlegroups .com>,
dated Wed, 4 Oct 2006 16:50:25 remote, seen in
news:comp.lang.javascript, web.dev <we********@gmail.composted :
>
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.
Oct 5 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Amir | last post: by
7 posts views Thread by mhk | last post: by
3 posts views Thread by phal | last post: by
4 posts views Thread by TJS | last post: by
5 posts views Thread by mouac01 | last post: by
2 posts views Thread by daniel.boorn | last post: by
27 posts views Thread by Chris | last post: by
1 post views Thread by ll | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.