472,345 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,345 software developers and data experts.

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 12640

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Amir | last post by:
I'm looking for an example of form validation by JavaScript before it's processed by a PHP script. Any help will be appreciated.
2
by: francisco lopez | last post by:
Yesterday I had a problem with a javascript to validate my form, but you helped my out yesterday and it works now perfectly!!! so thank you!!! ...
7
by: mhk | last post by:
Hi, Is there any way to create/set Session veriable in JavaScript. Please let me know if anyone has an idea. Thanks alot.
3
by: phal | last post by:
Hi all; I code Perl for CGI, I using regular expression to check the validation of user input, because the form is small and it run only from...
4
by: TJS | last post by:
how do I get "onSubmit" to work in .net ? <Form id="Form1" name="Form1" method="post" onSubmit="return validateStandard(this, 'error');"...
5
by: mouac01 | last post by:
I'm new to PHP/Javascript. I have a simple form I want to validate the fields with javascript and then run the PHP script. All the scripts are in...
2
by: daniel.boorn | last post by:
Form validation using JavaScript has never been as easy and simple! We have developed a free generic form validation script that can validate any...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of...
1
by: ll | last post by:
Hi, I am working with a page that has both cfform elements and 'plain html' form elements. In particular, I am needing to validate my textarea...
3
by: happyse27 | last post by:
Hi All, I am creating the perl script using html form(with embedded javascript inside). When using this html form with javascript alone, it...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.