473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

IE7 ignores my javascript validation

Hi

I'm struggling finding a reason why this is happening in IE7...

I have a simple form such as:

Expand|Select|Wrap|Line Numbers
  1. <html> 
  2. <head> 
  3. <script type="text/javascript"> 
  4. function validate_required(field,alerttxt) { 
  5.     with (field)   {   
  6.         if (value==null||value=="")     {     
  7.             alert(alerttxt);
  8.             return false;     
  9.             }   
  10.         else {     
  11.             return true;     
  12.             }   
  13.         } 
  14.     } 
  15.  
  16. function validate_form(thisform) { 
  17.     with (thisform)   {   
  18.         if (validate_required(email,"Email must be filled out!")==false)   { 
  19.             email.focus();
  20.             return false;
  21.             }   
  22.         } 
  23. </script> 
  24. </head>  
  25. <body> 
  26. <form action="submit.htm" onsubmit="return validate_form(this)" method="post"> 
  27. Email: <input type="text" name="email" size="30"> <input type="submit" value="Submit"> 
  28. </form> 
  29. </body>  
  30. </html> 
  31.  
When not entering anything in the email field the javascript detects it and the alert message is displayed BUT as soon as you click OK the form is submitted/processed to the action page "submit.htm".

Does anyone know why this is happening under IE7 it does work fine with Firefox though...?

The same happens for many of my forms.

Thanks for any input, I'm really struggling at the moment
May 9 '11 #1
1 1507
acoder
16,027 Expert Mod 8TB
I'm not sure if this will make a difference (I haven't tested), but try removing the use of "with" and access the fields directly.
May 10 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: JJ_377 | last post by:
I want a JavaScript validation function to fire on an ASP.NET textbox's change event. Here's what I've been trying and it is not working. The following added in the webform's page load event: ...
3
by: Mike P | last post by:
I have a method that I use for Javascript validation (see below). What I want to do is change the alert title, buttons, icon etc. Does anybody know the correct syntax to do this? private void...
8
by: vunet.us | last post by:
Why does IE6 ignores JavaScript's return false on a link and how to fix it? Firefox works perfect! <a href="page1.html" onclick="return test(this)">Test</a> JS: function test(obj) {...
1
by: karen987 | last post by:
I have a comment form, on a news website, ASP page, which users fill in and it adds comments to a news article. The reader clicks on a headline and the comments open up in a new window. It already...
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 form field and my email text field. On one of my...
1
by: shrin | last post by:
Hi all, I want to use asp.net validator and javascript validation function on a single form for different fields. also I want to execute some code on button click after the validation is completed....
21
by: kiran83 | last post by:
My Text box can accept all types of data like alphabets,numeric,special characters ... Should give an error message 'if space is not a valid value ' when i am clicking a button... in asp.net with...
1
by: jerrydigital | last post by:
Hello, I have a form that i use ASP to process the form to my access database. It works well but I'm struggling to get the javascript validation to work. I have posted a small version of my form...
12
by: btreddy | last post by:
Hii Experts, im facing a problem with the javascript validation.i've a gridview in my web form and added a footer tempalte and placed textboxes in tht tempalte ,just to add a new row to the...
3
by: gayuvinu | last post by:
Hi, I am new to javascript, I need your help in javascript validation of a string. string of length 6, last 4 characters can be padded with "8" while entering. valid strings are ZJJL74 ZJJL7*...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.