473,324 Members | 2,548 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,324 software developers and data experts.

form validation not working in both IE and Firefox.

tharini
I have a simple form with four fields. The validation code for these fields are not working properly in both IE and firefox.I have given the code below.Please tell me whats the problem.


Expand|Select|Wrap|Line Numbers
  1.  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Untitled Document</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <style type="text/css">
  7. <!--
  8. .content {
  9. overflow: auto;
  10. width: 400px;
  11. height:200px;
  12. }
  13. -->
  14. </style>
  15. <script language="javascript" type="text/javascript" >
  16. function checkvals(){
  17.     if (document.myFRM.name.value=="NULL"){
  18.             alert("Please Enter the Name field.");
  19.             document.myFRM.name.focus();
  20.             return false;
  21.     } else if (document.myFRM.mobile.value=="NULL"){
  22.             alert("Please Enter a valid Mobile Number.");
  23.             document.myFRM.mobile.focus();
  24.             return false;
  25.     } else if (document.myFRM.email.value=="NULL") { 
  26.       alert("Please enter a valid email address.");
  27.       document.myFRM.email.focus();
  28.             return false;
  29.     } else if (document.myFRM.message.value=="NULL") {
  30.             alert("Please Enter the Message Field.");
  31.             document.myFRM.message.focus();
  32.             return false;
  33.     } else {
  34.         return true;
  35.     }
  36. }
  37. </script>
  38. </head>
  39.  
  40. <body>
  41. <table width="720" height="585" border="0" align="center" cellpadding="0" cellspacing="0">
  42.   <tr>
  43.     <th scope="col"><form  method="post" name="myFRM" id="myFRM"  onSubmit="return checkvals()" action="">
  44.       <table width="553" height="478" border="0" cellpadding="0" cellspacing="0">
  45.         <tr>
  46.           <th height="52" colspan="4" scope="col">&nbsp;</th>
  47.           </tr>
  48.         <tr>
  49.           <th width="85" height="41" scope="row">&nbsp;</th>
  50.           <td width="136"><div align="right">Name:</div></td>
  51.           <td width="10">&nbsp;</td>
  52.           <td width="322"><input name="name" type="text" id="name"></td>
  53.         </tr>
  54.         <tr>
  55.           <th height="37" scope="row">&nbsp;</th>
  56.           <td><div align="right">Mobile No.:</div></td>
  57.           <td>&nbsp;</td>
  58.           <td><input name="mobile" type="text" id="mobile"></td>
  59.         </tr>
  60.         <tr>
  61.           <th height="37" scope="row">&nbsp;</th>
  62.           <td><div align="right">E-Mail:</div></td>
  63.           <td>&nbsp;</td>
  64.           <td><input name="email" type="text" id="email"></td>
  65.         </tr>
  66.         <tr>
  67.           <th height="221" scope="row">&nbsp;</th>
  68.           <td><div align="right" class="style1">Message:</div></td>
  69.           <td>&nbsp;</td>
  70.           <td><textarea name="message" class="content" id="message"></textarea></td>
  71.         </tr>
  72.         <tr>
  73.           <th scope="row">&nbsp;</th>
  74.           <td>&nbsp;</td>
  75.           <td>&nbsp;</td>
  76.           <td><input type="submit" name="Submit" value="Submit"></td>
  77.         </tr>
  78.       </table>
  79.     </form></th>
  80.   </tr>
  81. </table>
  82. </body>
  83. </html>
  84.  
Sep 6 '10 #1

✓ answered by gits

the value of an empty textfield isn't "NULL" ... it is an empty string "" ... so if you want to check for empty values you might either test for the shown empty string or > 0.

you might even trim the value to check for only whitepaces or use regular expressions to check for whatever characters shouldn't/should be valid in the fields.

2 1587
gits
5,390 Expert Mod 4TB
the value of an empty textfield isn't "NULL" ... it is an empty string "" ... so if you want to check for empty values you might either test for the shown empty string or > 0.

you might even trim the value to check for only whitepaces or use regular expressions to check for whatever characters shouldn't/should be valid in the fields.
Sep 6 '10 #2
kovik
1,044 Expert 1GB
By ">0", I assume he means the .length property of the string.
Sep 6 '10 #3

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

Similar topics

3
by: Skippytpe | last post by:
Does anyone have an idea why the form validation in the following page wouldn't be working? I had been using XHTML 1.0 transitional which allowed me to use the form attribute 'name.' I could then...
3
by: Robert Smith | last post by:
I have a very basic form validation script, which wont work due to XHTML Strict not allowing me to use the name attribute on a form. Here is part of my code: if...
3
by: n3mtkj3mzsir0cy | last post by:
I have created web pages that do client-side form validation using the onclick directive. E.g., <form action=other_page.cgi method=post> Enter your age: <input name=age> <input type="submit"...
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 Javascript form validation functions, but it...
2
by: Niraj Sikotara | last post by:
hello, i'm using ASP.NET 2.0, and have placed validators on a page that are not working correctly in FireFox (1.5.0.7) the page can be downloaded from...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
5
by: kuyaboj | last post by:
Hi all, I'm trying to implement this script so that it works for both Firefox and IE. The function works properly in Firefox but in IE, it hangs. What am I doing wrong? <script...
3
by: localhost1 | last post by:
i have a serious probem in javascript form validation. i have written a validation code in javascript. it working in internet explorer 7 but the same code is not working in mozilla firefox. what...
1
by: Nirmal Vasanth | last post by:
Hi., I am working .NetFramework1.1.i use Asp.net1.1 server validation controls its working IE but not working in Firefox browser. Please give me a solution..
3
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.