By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,318 Members | 2,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,318 IT Pros & Developers. It's quick & easy.

Javascript form validation script- not defined in Mozilla Firefox

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a

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

P: n/a
<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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
"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

P: n/a

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

P: n/a
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.