473,412 Members | 5,361 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,412 software developers and data experts.

form validation code works in IE7, but not in Firefox

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 could be the reason??
Sep 6 '07 #1
3 1646
acoder
16,027 Expert Mod 8TB
Changed the thread title. Please use good thread titles.

Post your problem code.
Sep 6 '07 #2
hi
thnks for ur reply
my code goes like this
Expand|Select|Wrap|Line Numbers
  1. <form method="post" action="recruitment.php" name="job">
  2.           <tr>
  3.  
  4.             <td align="left" valign="top" ><table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
  5.               <tr>
  6.                 <td height="30" colspan="2" align="left" class="content" style=" height:25px"><span class="content3" style=" height:25px">Nom*:</span><span class="content" style=" height:25px"><span class="content" style=" height:25px"><span class="content" style=" height:25px"><span class="content" style=" height:25px"><span class="content" style=" height:25px"><span class="content" style=" height:25px">
  7.                   <input type="text" name="recrut_nom" class="required"  style=" height:15px; width:495px; border:1px solid #EB208D"/>
  8.                 </span></span></span></span></span></span></td>
  9.               </tr>
  10.               <tr>
  11.                 <td height="30" colspan="2" align="left" class="content" style=" height:25px"><span class="content3">Prenom*:</span><span class="content" style=" height:25px"><span class="content" style=" height:25px">
  12.                   <input type="text" name="recrut_prenom" class="required"  style=" height:15px; width:474px; border:1px solid #EB208D"/>
  13.                 </span></span></td>
  14.                 </tr>
  15.               <tr>
  16.                 <td height="30" colspan="2" align="left" class="content"  style=" height:25px"><span class="content3">Adresse complete* :</span><span class="content" style=" height:25px">
  17.                   <input type="text" name="recrut_address1" class="required"  style=" height:15px; width:406px; border:1px solid #EB208D"/>
  18.                   <br />
  19.                   <span class="content" style=" height:25px">
  20.                   <input type="text" name="recrut_address2" class="required"  style=" height:15px; width:536px; border:1px solid #EB208D"/>
  21.                   </span>                </span></td>
  22.                 </tr>
  23.               <tr>
  24.                 <td height="30" colspan="2" align="left" class="content"  style=" height:25px"><span class="content3">Code Postal *: </span><span class="content" style=" height:25px">
  25.                   <input type="text" name="recrut_postal" class="required_numeric"  style=" height:15px; width:442px; border:1px solid #EB208D"/>
  26.                 </span></td>
  27.               </tr>
  28.               <tr>
  29.                 <td height="30" colspan="2" align="left"  style=" height:25px; padding-right:15px"><span class="content3">ViIIe*:</span>
  30.                   <input name="recrut_ville" class="required" type="text"   style=" height:15px; width:490px; border:1px solid #EB208D"/>
  31.                 <br /></td>
  32.               </tr>
  33.               <tr>
  34.                 <td height="30" colspan="2" align="left" class="content"  style=" height:25px; padding-right:15px"><span class="content3">Mail*:&nbsp;</span><span class="content" style=" height:25px">
  35.                   <input type="text" name="recrut_mail" class="email"  style=" height:15px; width:494px; border:1px solid #EB208D"/>
  36.                 </span><br /></td>
  37.               </tr>
  38.               <tr>
  39.                 <td height="30" colspan="2" align="left" class="content3"  style=" height:25px; padding-right:15px">T&eacute;l&eacute;phone Fixe : <span class="content" style=" height:25px">
  40.                   <input type="text" name="recrut_phone" class="required_numeric"  style=" height:15px; width:429px; border:1px solid #EB208D"/>
  41.                 </span></td>
  42.               </tr>
  43.               <tr>
  44.                 <td height="30" colspan="2" align="left"  style=" height:25px; padding-right:15px"><span class="content3">Portable:</span><span class="content" style=" height:25px">
  45.                   <input type="text" name="recrut_mobile" class="required_numeric"  style=" height:15px; width:475px; border:1px solid #EB208D"/>
  46.                 </span><br /></td>
  47.               </tr>
  48.               <tr>
  49.                 <td width="13%" align="left" valign="top" class="content"  style=" height:25px; padding-right:15px"><span class="content3">Experiences:</span><br /></td>
  50.                 <td width="87%" align="left" valign="top"  style=" height:25px; padding-right:15px"><span class="content" style=" height:25px">
  51.                   <input type="text" name="recrut_experience" class="required"  style=" height:107px; width:441px; border:1px solid #EB208D"/>
  52.                 </span></td>
  53.               </tr>
  54.               <tr>
  55.                 <td align="left" class="content3"  style=" height:25px; padding-right:15px">Dons* </td>
  56.                 <td align="left" class="content"  style=" height:25px; padding-right:15px"><input type="checkbox" name="recrut_sensitif" value="1" />
  57.                   <span class="content3">                  Sensitif</span> 
  58.                     <input type="checkbox" name="recrut_auditif" value="1" />
  59.                     <span class="content3">Auditif</span>
  60.                     <input type="checkbox" name="recrut_ecrivian" value="1" />                    <span class="content3">&Eacute;crivan</span> 
  61.                     <input type="checkbox" name="recrut_tarots" value="1" />
  62.                     <span class="content3">Tarots</span> </td>
  63.               </tr>
  64.               <tr>
  65.                 <td align="left"  style=" height:25px; padding-right:15px">&nbsp;</td>
  66.                 <td align="left" class="content"  style=" height:25px; padding-right:15px"><span class="content3">Autres :</span> <span class="content" style=" height:25px">
  67.                   <input type="text" name="recrut_autres"  style=" height:15px; width:388px; border:1px solid #EB208D"/>
  68.                 </span></td>
  69.               </tr>
  70.               <tr>
  71.                 <td colspan="2" align="right"  style=" height:25px; padding-right:15px"><input type="submit" name="jobsubmit" runat="server"  value="ENVOYER" class="btn"  onclick="return validateForm();"></td>
  72.               </tr>
  73.               <tr>
  74.                 <td colspan="2" align="right"  style=" height:25px; padding-right:15px">&nbsp;</td>
  75.               </tr>
  76.             </table></td>
  77.  
  78.           </tr>
  79.           </form>
and the javascript code goes like this
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function validateForm()
  3. {
  4.     alert("inside javascript");
  5.     var a = Array();
  6.     var oInputs = job.getElementsByTagName("input");
  7.     n = oInputs.length;
  8.     for(i = 0; i < n; i++)
  9.     {
  10.         if (oInputs[i].type == "text" && (oInputs[i].className).substr(0,8) == "required")
  11.         {
  12.         if (oInputs[i].value=="") 
  13.             {
  14.                 alert ("Please enter all the required fields on "+ oInputs[i].name);
  15.                 oInputs[i].focus();
  16.                 return false;
  17.             }
  18.         switch (oInputs[i].className)
  19.             {
  20.             case "required_numeric":
  21.                 if (isNaN(oInputs[i].value))
  22.                 {
  23.                     alert ("Please enter Numeric Value on " + oInputs[i].name);
  24.                     oInputs[i].focus();
  25.                     return false;
  26.                 }
  27.                 break;
  28.  
  29.             }
  30.  
  31.         }
  32.         else if(oInputs[i].type == "text" && (oInputs[i].className).substr(0,8) == "price")
  33.         {
  34.             if (isNaN(oInputs[i].value))
  35.                 {
  36.                     alert ("Please Enter Correct Price on  " + oInputs[i].id);
  37.                     oInputs[i].focus();
  38.                     return false;
  39.                 }
  40.         }
  41.         else if  (oInputs[i].type=="checkbox" && (oInputs[i].className).substr(0,14) == "required_group")
  42.         {
  43.             var cSearch = oInputs[i].className;
  44.             var searchObjects = job.getElementsByTagName("input");
  45.             n1 = searchObjects.length; 
  46.             da=0
  47.             for(c = 0; c < n1; c++)
  48.             {
  49.  
  50.                 if ( searchObjects[c].type=="checkbox" && searchObjects[c].className==cSearch )
  51.                 {
  52.                     if (searchObjects[c].checked) da=1
  53.                 }
  54.             }
  55.             if (da==0) 
  56.             {
  57.                 alert("Please select at least one value...")
  58.                 oInputs[i].focus();
  59.                 return false;
  60.             }
  61.  
  62.         }
  63.         else if  (oInputs[i].type=="text" && (oInputs[i].className).substr(0,5) == "email")
  64.         {
  65.             /*var cSearch = oInputs[i].className;
  66.             var searchObjects = formID.getElementsByTagName("input");
  67.             n1 = searchObjects.length; */
  68.             var emailID=document.job.recrut_mail
  69.             //var emailconfID=document.forpass.user_password
  70.  
  71.             if ((emailID.value==null)||(emailID.value=="")){
  72.             alert("Please Enter your Email ID")
  73.             emailID.focus()
  74.             return false
  75.         }
  76.         if (echeck(emailID.value)==false){
  77.             emailID.value=""
  78.             emailID.focus()
  79.             return false
  80.         }
  81.         return true
  82.  
  83.         }
  84.  
  85.  
  86.     }
  87.  
  88. }
  89.  
  90.  
  91. function echeck(str) {
  92.  
  93.         var at="@"
  94.         var dot="."
  95.         var lat=str.indexOf(at)
  96.         var lstr=str.length
  97.         var ldot=str.indexOf(dot)
  98.         if (str.indexOf(at)==-1){
  99.            alert("Invalid E-mail ID")
  100.            return false
  101.         }
  102.  
  103.         if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
  104.            alert("Invalid E-mail ID")
  105.            return false
  106.         }
  107.  
  108.         if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
  109.             alert("Invalid E-mail ID")
  110.             return false
  111.         }
  112.  
  113.          if (str.indexOf(at,(lat+1))!=-1){
  114.             alert("Invalid E-mail ID")
  115.             return false
  116.          }
  117.  
  118.          if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
  119.             alert("Invalid E-mail ID")
  120.             return false
  121.          }
  122.  
  123.          if (str.indexOf(dot,(lat+2))==-1){
  124.             alert("Invalid E-mail ID")
  125.             return false
  126.          }
  127.  
  128.          if (str.indexOf(" ")!=-1){
  129.             alert("Invalid E-mail ID")
  130.             return false
  131.          }
  132.  
  133.           return true                    
  134.     }
  135.  
  136.  
  137. </script>
Sep 6 '07 #3
acoder
16,027 Expert Mod 8TB
On line 6 in your Javascript, you're referring to "job" without first accessing the form object using, e.g.
Expand|Select|Wrap|Line Numbers
  1. document.forms["job"]
Sep 6 '07 #4

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

Similar topics

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...
4
by: John Fereira | last post by:
So, one of the limitations of multipart-form handling is that when an <input type="file" ..> tag is used it will bring up a window which allows a user to select a file for upload but won't allow...
1
by: Zvonko | last post by:
Hi! T This is the code: <script type="text/javascript"> function Provjeri(i) { var poruka = ""; if (i.ime.value=="") { poruka+="* Nedostaje Ime i Prezime!\n";
4
by: Andre | last post by:
Hi, I have read at many place that .Net 2.0 was suppose to support client-side validation in non-IE Browser. But i've try a very simple validation, and firefox is unable to run it, it works only...
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...
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...
6
by: shapper | last post by:
Hello, I am creating a form that includes a few JQuery scripts and TinyMCE Editor: http://www.27lamps.com/Beta/Form/Form.html I am having a few problems with my CSS: 1. Restyling the Select
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.