473,508 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript form validation code works in IE but not in Mozilla-Firefox

14 New Member
I hv following javascript form validation code works in IE but not in Mozilla-Firefox ...please suggest

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function IsNumeric(strString)
  3.    //  check for valid numeric strings    
  4.    {
  5.    var strValidChars = "0123456789.-";
  6.    var strChar;
  7.    var blnResult = true;
  8.  
  9.    if (strString.length == 0) return false;
  10.  
  11.    //  test strString consists of valid characters listed above
  12.    for (i = 0; i < strString.length && blnResult == true; i++)
  13.       {
  14.       strChar = strString.charAt(i);
  15.       if (strValidChars.indexOf(strChar) == -1)
  16.          {
  17.          blnResult = false;
  18.          }
  19.       }
  20.    return blnResult;
  21.    }
  22. function valid_form()
  23. {
  24.  
  25.     var emailfilter=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/
  26.     var e=document.getElementById('form').email.value
  27.     var tphone=document.getElementById('form').phone.value;
  28.     var returnval=emailfilter.test(e)
  29.     var cityw=document.getElementById('form').country.value;
  30.     var tname=document.getElementById('form').name.value;
  31.     var query=document.getElementById('form').textfield2.value;
  32.  
  33.     if(query=="")
  34.     {
  35.         alert("Please specify your requirement.")    
  36.         document.getElementById('form').textfield2.focus();
  37.  
  38.         return false;
  39.     }
  40.  
  41.  
  42.     if(tname=="")
  43.     {
  44.         alert("Please enter your name.")
  45.         document.getElementById('form').name.focus();
  46.         return false;
  47.     }
  48.  
  49.  
  50.     if(e=="")
  51.     {
  52.         alert("Please enter your email.")
  53.         document.getElementById('form').email.focus();
  54.         return false;
  55.     }
  56.  
  57.     if(returnval==false)
  58.     {
  59.         alert("Please enter your valid email.")
  60.             document.getElementById('form').email.focus();
  61.         return false;
  62.     }
  63.         if(tphone==false)
  64.     {
  65.         alert("Please enter your phone number.")
  66.         document.getElementById('form').phone.focus();
  67.         return false;
  68.     }
  69.      if (IsNumeric(tphone)==false){
  70.               alert(" Please enter a valid phone number.");
  71. document.getElementById('form').phone.focus();
  72.         return false
  73.     }
  74.  
  75.     if(cityw=="")
  76.     {
  77.         alert("Please select your country.")
  78.         document.getElementById('form').focus();
  79.         return false;
  80.     }
  81.  
  82.  
  83. }
  84.  </script>
Apr 13 '09 #1
3 5547
RamananKalirajan
608 Contributor
You have used "document.getElementById('form')". Just check this one.. Have you given an id attribute to the form ie. <form name="form" id="form">. In IE if u have given name it will automatically take as ID, but mozilla wont take it.. Just Check that one.. I havent checked ur js code.. This is the common mistake i would do when i started working on scripts. If this is not ur problem, post the html code also...

Regards
Ramanan Kalirajan
Apr 13 '09 #2
acoder
16,027 Recognized Expert Moderator MVP
It's easy to avoid that mistake by never testing on IE first unless you want to develop bad coding habits and plenty of headaches later.

OP: your isNumeric function needs a bit of adjustment. It allows multiple - and . which would not be a valid numeric value.
Apr 13 '09 #3
PrabodhanP
14 New Member
Thank you ,very much sir for quick reply...it works fine now


@RamananKalirajan
Apr 16 '09 #4

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

Similar topics

0
7125
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
7388
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...
1
7049
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
7499
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...
0
5631
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,...
0
3199
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...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
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 ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.