473,770 Members | 4,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form validation script works in IE but not Mozilla

Hi
I hope someone can help me. I have a client side form validation script
which works perfectly in IE but clicking "Submit" in Mozilla does
nothing - the form won't submit.
Is there something I can use that will work for both browsers, or is
there something wrong with my code? I seem to think that the problem
lies with the "onclick" area of the form.
This is my code, such as it is...

<SCRIPT LANGUAGE="JavaS cript">
function ValidateEntries () {

if (MyForm.InputNa me.value == "") {
alert ("\nPlease enter your first name.")
return false;
}

if (MyForm.InputSu rname.value == "") {
alert ("\nPlease enter your Surname.")
return false;
}

if ((MyForm.InputE mail.value == "") ||
(MyForm.InputEm ail.value.index Of('@') == -1) ||
(MyForm.InputEm ail.value.index Of('.') == -1)) {
alert ("\nPlease enter your Email Address.")
return false;
}

if (MyForm.InputAd dress.value == "") {
alert ("\nPlease enter your Address.")
return false;
}

if (MyForm.InputPo stalcode.value == "") {
alert ("\nPlease enter your Postalcode.")
return false;
}

if (MyForm.InputTe lephoneNumber.v alue == "") {
alert ("\nPlease enter your Telephone Number.")
return false;
}

if (MyForm.InputCo mments.value == "") {
alert ("\nPlease type your Comments.")
return false;
}
else return document.MyForm .submit();
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled </title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1"></head>

<body bgcolor="#CCCCC C" leftmargin="5" topmargin="0">
<Form name="MyForm" action="sendmai l.asp" method="post">

<table width="534" border="0" cellpadding="0" cellspacing="0" >
<tr>
<td valign="top"><f ont size="2" face="Arial, Helvetica,
sans-serif">Name
: </font></td>
<td valign="top"><i nput type="text" name="InputName "></td>
</tr>
<tr>
<td valign="top"><f ont size="2" face="Arial, Helvetica,
sans-serif">Surname
: </font></td>
<td valign="top"><i nput type="text" name="InputSurn ame"></td>
</tr>
<tr>
<td valign="top"><f ont size="2" face="Arial, Helvetica,
sans-serif">e-mail
Address: </font></td>
<td valign="top"><i nput type="text" name="InputEmai l"></td>
</tr>
<tr>
<td valign="top"><f ont size="2" face="Arial, Helvetica,
sans-serif">Physical
Address : </font></td>
<td valign="top"><t extarea name="InputAddr ess" rows="5"
cols="30"></textarea></td>
</tr>
<tr>
<td valign="top"><f ont size="2" face="Arial, Helvetica,
sans-serif">Postal
code : </font></td>
<td valign="top"><i nput type="text" name="InputPost alcode"></td>
</tr>
<tr>
<td valign="top"><f ont size="2" face="Arial, Helvetica,
sans-serif">Telephon e
Number : </font></td>
<td valign="top"><i nput type="text"
name="InputTele phoneNumber"></td>
</tr>
<tr>
<td valign="top"><f ont size="2" face="Arial, Helvetica,
sans-serif">Message
: </font></td>
<td valign="top"><t extarea name="InputComm ents" rows="5"
cols="30"></textarea></td>
</tr>
<tr>
<td colspan="2" valign="top"> <input type="button" value="Submit"
onclick="Valida teEntries()">
</td>
</tr>
</table>
</Form>
</body>

If anyone could help me, I would seriously reconsider dashing my
forehead against the desk
</thanks>

Jul 23 '05 #1
2 2308
we********@hype rlink.co.za writes:
I have a client side form validation script which works perfectly in
IE but clicking "Submit" in Mozilla does nothing - the form won't
submit.
Then you are doing something wrong. It should submit, just without
the validation, otherwise it won't work if Javascript is turned off.
Is there something I can use that will work for both browsers, or is
there something wrong with my code?
It's your code.
<SCRIPT LANGUAGE="JavaS cript">
Should be
<script type="text/javascript">
The type attribute is required by HTML, and is always sufficient.
function ValidateEntries () {

if (MyForm.InputNa me.value == "") {
You have not declared a variable called MyForm. You assume that your
browser will create a global variable for your named form. Not all
browsers do that (IE does, Mozilla doesn't).

When referring to a form called "MyForm", always use:
document.forms['MyForm']
To save typing, you can assign the form reference to a variable:

var myForm = document.forms['MyForm'];

Then do
if (myForm.element s['InputName'].value == "") {

Ditto for the remaining tests.
(You could collect all the errors in one go, instead of only
showing the first one. That would speed up the user)

.... else return document.MyForm .submit();
There should be no need for this, just return true, if you
make your page to work without javascript enabled.
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
ICK. There should not be anything before the DOCTYPE declaration
in an HTML page. In particular, script elements are only valid
inside the HEAD and BODY elements. Please make your HTML validate!
<Form name="MyForm" action="sendmai l.asp" method="post"> .... <input type="button" value="Submit" onclick="Valida teEntries()">


This only works if Javascript is enabled. On the other hand, pressing
return in one of the text fields might submit the form without any
validation. A better approach is:

---
<form ... onsubmit="retur n ValidateEntries ();">
...
<input type="submit" value="Submit">
---

Good luck.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
Lasse Reichstein Nielsen wrote:
To save typing[...]
and increase efficiency,
you can assign the form reference to a variable: [...]

PointedEars
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9984
by: TG | last post by:
I have a validation form that must behave differently based on the results of a PHP validation check. I have a post command at the top of my form that calls itself. I don't leave the form when performing the validation check on the values that were entered into the form, I simply repost the form to perform the PHP validation. If any of the values that have been entered into the form are incorrect, I display a warning message on the screen...
1
6022
by: Lukelrc | last post by:
Hi, I have a form containing (among other things) date fields for which i have a date validation script. What i need to happen is when the user presses the submit button the date validation script is run and only if the date is correct is the form submited. What i have done so far is: -Chagned the button type from 'submit' to 'button'
7
2992
by: greg brant | last post by:
i have a form made up of 2 file inputs and a submit button.. the imputs are to upload images, namley jpeg's for a e-greatings thing im working on. this only works with jpegs so i have a script that will check the value of the imput tag to make sure it ends with .jpg, .jpeg. this works fine on the jubmit button using onclick="myHandler(this)"
6
1937
by: Drew | last post by:
I've already created a simple method of ensuring that all form feilds are filled out before the form is submitted to an ASP page for records to be added to the data base. (Sorry about the formating, my newsreader may make it a mess!) <script language="javascript"> <!-- function Check(form) {
3
13140
by: Earl Teigrob | last post by:
I wanted my "Terms and Conditions" Checkbox control to participate in my ASP.NET validation just like all the the other controls on the page. After some time of searching the web for an example of how to do this, I created the script to do it and thought I would share it. Its a littel messy but does the job. If anyone has a better solution, please let me know. //Client Site Event Handler to put in Page_Load event...
5
304
by: raagz | last post by:
Hi, I am using the .NET validation controls for validating . The validation works fine with IE but none of them work with Netscape 6 browser. Do i have to configure something in vS.NET to make the validations work in Netscape too or is it .net validation controls dont work with Netscape.
27
4754
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 Javascript form validation functions, but it appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
8
12728
by: nektir | last post by:
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 == "%")) {
3
5557
by: PrabodhanP | last post by:
I hv following javascript form validation code works in IE but not in Mozilla-Firefox ...please suggest <script type="text/javascript"> function IsNumeric(strString) // check for valid numeric strings { var strValidChars = "0123456789.-"; var strChar; var blnResult = true;
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.