By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,036 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,036 IT Pros & Developers. It's quick & easy.

onfocus() is working fine in IE but not in Firefox

P: 10
Hi,

I have validate a text field with onchange event which throw error message, if
not satisfied the condition and set the mouse cursor on the same field using
document.focus().

It is working fine in IE, but when used in Firefox, the mouse cursor is moving to the next text field.

Please let me know the possible solution for the above problem.

Regards and Thanks

Sourav
Jul 1 '08 #1
Share this Question
Share on Google+
14 Replies


acoder
Expert Mod 15k+
P: 16,027
Post your problem code.
Jul 1 '08 #2

P: 10
The below function validates a text field which only accepts space and letters.

Expand|Select|Wrap|Line Numbers
  1. function Climit()
  2.  { 
  3.  
  4.  var find=/[0-9\*\=\_\>\<\:\@\&\%\?\$\)\(\`\~\#\^\|\+\.\,\;\\\}\{\]\[\\"\!\/\-\']/;
  5.    var maxchars=20;
  6.  
  7.  if(document.personal.person_name.value.length > maxchars) 
  8.  {
  9.    alert('Too much data in the text box! Please remove '+
  10.     (document.personal.person_name.value.length - maxchars)+ ' characters');
  11.  
  12.             window.document.personal.person_name.focus();
  13.             window.document.personal.person_name.select();
  14.    return false;
  15.     }
  16.  
  17.  
  18.  else if(document.personal.person_name.value.search(find)!= -1)
  19.         {
  20.             alert("Only letters are allowed.");
  21.             window.document.personal.person_name.focus();
  22.             window.document.personal.person_name.select();
  23.             return false;
  24.         }
  25.         else
  26.    return true; 
  27.  }
  28.  
The focus() is working fine in IE but not in Firefox.

Thanks

Sourav
Jul 1 '08 #3

acoder
Expert Mod 15k+
P: 16,027
Also post the corresponding HTML code. Please use code tags when posting code (See How to Ask a Question). Thanks!
Jul 1 '08 #4

P: 10
Expand|Select|Wrap|Line Numbers
  1. <tr>
  2.     <td width="133"><div align="left"><span class="style30">*&nbsp;</span><span class="style26">Name</span></div></td>
  3.     <td width="270" align="left"><input type="text" name="person_name" id="person_name"  value="" style=" text-transform: capitalize;" class="blurField" onFocus="if(this.value=='Enter Name') this.value=''; this.className='focusField'" onBlur="blurCName();" onchange="return Climit();"></td> 
  4.  
  5. <script language="javascript">
  6.  
  7.  
  8. function blurCName()
  9. {   
  10.   if(document.personal.person_name.value=='')
  11.  {
  12.    document.personal.person_name.value='Enter Name';
  13.   document.personal.person_name.className='blurField';
  14.  // document.personal.person_name.focus();
  15.   //document.personal.person_name.select();
  16.     return true;
  17.   }
  18.   else
  19.         //document.personal.person_name.focus();
  20.   return false;
  21. }
  22.  
  23.  
  24. function Climit()
  25.  { 
  26.      //obj = document.getElementById('person_name');
  27.     //obj.value = (obj.value).replace(/^\s+/, '').replace(/\s+$/, '');
  28.  
  29.  var find=/[0-9\*\=\_\>\<\:\@\&\%\?\$\)\(\`\~\#\^\|\+\.\,\;\\\}\{\]\[\\"\!\/\-\']/;
  30.    var maxchars=20;
  31.  
  32.  if(document.personal.person_name.value.length > maxchars) 
  33.  {
  34.    alert('Too much data in the text box! Please remove '+
  35.     (document.personal.person_name.value.length - maxchars)+ ' characters');
  36.  
  37.             window.document.personal.person_name.focus();
  38.             window.document.personal.person_name.select();
  39.    return false;
  40.     }
  41.  
  42.  
  43.  else if(document.personal.person_name.value.search(find)!= -1)
  44.         {
  45.             alert("Only letters are allowed.");
  46.             window.document.personal.person_name.focus();
  47.             window.document.personal.person_name.select();
  48.             return false;
  49.         }
  50.         else
  51.    return true; 
  52.  }
  53.  
  54. </script> 
  55. </tr>
Jul 2 '08 #5

acoder
Expert Mod 15k+
P: 16,027
You have an onchange and an onblur both trying to focus if there's an error. Why not just use just an onchange instead? It's more reliable and user-friendly and less annoying. See if that helps. I take it your form is called "personal", right?
Jul 2 '08 #6

P: 10
Hi,
Thanks for ur suggestion.
I have tried the code by omitting onblur event, but the focus problem still persist in Mozilla (when error occurs in the 1st input field).

Thanks & Regards,

Sourav
Jul 2 '08 #7

acoder
Expert Mod 15k+
P: 16,027
You will need to use a timeout to allow the focus back to the first field. I'm guessing you're tabbing to test the onchange/onblur. Try:
Expand|Select|Wrap|Line Numbers
  1. setTimeout(function() {document.personal.person_name.focus();},10);
Jul 2 '08 #8

P: 10
Hi,
Thanks for ur suggestion, but in Firefox, onchange event throws the error message using setTimeout and select that input field but focus is not working. In firefox focus can be set to the next field manually while it's not possible in IE.

Regards,
Sourav
Jul 2 '08 #9

acoder
Expert Mod 15k+
P: 16,027
Post all of the code or, if possible, a link to a test page.
Jul 2 '08 #10

P: 10
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("../config.php");
  3.  
  4. include("../session_check.php");
  5.  
  6. $ftchs=mysql_query("select admin_id from admin where admin_id='".$_SESSION['admin_id']."'")or die('Error'.mysql_error());
  7.  
  8. if (isset($_POST['submit']))
  9.  
  10.     {  
  11.        $contact_no= $_REQUEST['TelCC'].$_REQUEST['TelAC'].$_REQUEST['TelNo'];
  12.        $cntc = mysql_query("select contact_no from contact_details WHERE 
  13.        contact_no='$contact_no' AND admin_id='".$_SESSION['admin_id']."'") or die('Error'.mysql_error());
  14.  
  15.                   if(mysql_num_rows($cntc)!=0)
  16.                     {
  17.                       $duplicate_c="Please Don't Insert The Same Contact Person Twice";
  18.                     }
  19.  
  20.         else{
  21.           $admin_id=$_SESSION['admin_id'];
  22.           $person_name = $_REQUEST['person_name'];
  23.           $contact_no = $_REQUEST['TelCC'].$_REQUEST['TelAC'].$_REQUEST['TelNo'];
  24.           $alternative_contact = $_REQUEST['ATelCC'].$_REQUEST['ATelAC'].$_REQUEST['ATelNo'];
  25.           $email_Id = $_REQUEST['email_Id'];
  26.           $designation = $_REQUEST['designation'];
  27.           $address = $_REQUEST['address'];
  28.           $country=$_REQUEST['country'];
  29.           $zipcode=$_REQUEST['zipcode']; 
  30.           $other_details = $_REQUEST['other_details'];
  31.           $photo = $_FILES['photo']['name'];
  32.  
  33.  
  34.           $ins = mysql_query("INSERT INTO contact_details SET
  35.           admin_id = '".$_SESSION['admin_id']."', 
  36.           person_name='".$person_name."',
  37.           contact_no='".$contact_no."',
  38.           alternative_contact='".$alternative_contact."',
  39.           email_Id='".$email_Id."',
  40.           designation='".$designation."',
  41.           address='".$address."',
  42.           country='".$country."',
  43.           zipcode='".$zipcode."',
  44.           other_details='".$other_details."'") or die('Error .'.mysql_error());
  45.  
  46.           echo "admin_id=".$admin_id;
  47.  
  48.               if($_FILES['photo']['size'] >0 )
  49.                 {
  50.                     $person_id  =  mysql_insert_id();
  51.                     $photo = $person_id."_".$photo;
  52.                     copy($_FILES['photo']['tmp_name'], "../pictures/".$photo);
  53.                     $sql_update ="UPDATE contact_details SET photo='".$photo."' WHERE person_id='".$person_id."'";
  54.                     mysql_query($sql_update) or die ('Error '. mysql_error());
  55.                }
  56.     echo "<script>alert('Informations Inserted Successfully');window.location='../meeting/meetingdetails.php';</script>";       
  57.     }      
  58.     }
  59.  
  60. ?>
  61.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  6. <title>PersonalDocument</title>
  7.  
  8. <link href="../style.css" rel="stylesheet" type="text/css" />
  9.  
  10.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language="javascript">
  3.  
  4. function checkin()
  5. {  
  6.    if (document.personal.person_name.value=="" ||document.personal.person_name.value=="Enter Name")
  7.    {
  8.        alert("Please Insert Contact Person's Name");
  9.        window.document.personal.person_name.focus();
  10.        window.document.personal.person_name.select(); 
  11.        return false;
  12.    }
  13.  
  14.  if(document.personal.TelCC.value=="")
  15.   {
  16.   alert("Please provide correct country code");
  17.   window.document.personal.TelCC.focus();
  18.   return false;
  19.   }
  20.  
  21. if(document.personal.TelAC.value=="")
  22.   {
  23.   alert("Please provide correct area code");
  24.   window.document.personal.TelAC.focus();
  25.   return false;
  26.   }
  27.  
  28. if(document.personal.TelNo.value=="")
  29.   {
  30.   alert("Please provide correct phone number");
  31.   window.document.personal.TelNo.focus();
  32.   return false;
  33.   }
  34.  
  35.  
  36.    if (document.personal.designation.value=="")
  37.    {
  38.        alert("Please Insert Designation Of the Person")
  39.        window.document.personal.designation.focus();
  40.        window.document.personal.designation.select(); 
  41.        return false;
  42.    }
  43.    if (document.personal.address.value=="")
  44.    {
  45.        alert("Address Field Should Not Be Blank ")
  46.        window.document.personal.address.focus();
  47.        window.document.personal.address.select(); 
  48.        return false;
  49.    }
  50.  
  51.    if (document.personal.country.value=="")
  52.    {
  53.        alert("Country Field Should Not Be Blank ")
  54.        window.document.personal.country.focus();
  55.        //window.document.personal.country.select(); 
  56.        return false;
  57.    }
  58.  
  59.  
  60.  fileVal=window.document.personal.photo.value;
  61.             if(fileVal != "")
  62.                 {
  63.                         ext=fileVal.substr(fileVal.lastIndexOf(".")).toLowerCase();
  64.                         if(ext != ".jpeg"  && ext != ".jpg" && ext != ".gif" && ext!= ".bmp" ) 
  65.                         {
  66.                             alert("Please select a Specified Image File Type");
  67.                             window.document.personal.photo.focus();
  68.                             window.document.personal.photo.select();
  69.                             return false;
  70.                         }
  71.                 }        
  72.  
  73.    if (document.personal.other_details.value=="")
  74.    {
  75.        alert("Details About The Person?")
  76.        window.document.personal.other_details.focus();
  77.        window.document.personal.other_details.select(); 
  78.        return false;
  79.    }
  80.  
  81.    else
  82.      return true;
  83.  
  84.  }
  85.  </script>
  86.  
  87.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. </head>
  3.  
  4. <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
  5. <!-- ImageReady Slices (agenda info.psd) -->
  6.         <td colspan="8" rowspan="2" width="711" height="470">
  7.  
  8.  
  9.             <!--<img src="images/agenda-info_15.jpg" width="711" height="470" alt="">-->
  10.             <table width="516" height="471" align="center">
  11.               <tr>
  12.                 <td width="508" align="center" valign="top">
  13.                 <fieldset> <div align="left">
  14.         <legend class="style26 style32" style="border:#135879"><strong>Insert Personal
  15.   Details</strong></legend>
  16.       </div>
  17.      <table width="465" height="326"  align="center" border="0">
  18. <form action="" name="personal" method="post"  enctype="multipart/form-data" onsubmit="return checkin();" >
  19.  
  20.   <tr>
  21.     <td width="133"><div align="left"><span class="style30">*&nbsp;</span><span class="style26">Name</span></div></td>
  22.     <td width="270" align="left"><input name="person_name" type="text" id="person_name"  value="<?php echo($_POST['person_name']!=''?$_POST['person_name']:'Enter Name');?>" style=" text-transform: capitalize;" class="blurField" onFocus="if(this.value=='Enter Name') this.value=''; this.className='focusField'" onBlur="return blurCName()"; onchange="return Climit();" >    </td>
  23.  
  24.  
Expand|Select|Wrap|Line Numbers
  1.  
  2.     <script language="javascript">
  3.  
  4.  
  5. function blurCName()
  6. {   
  7. //"
  8.   {
  9.     obj = document.getElementById('person_name');
  10.  
  11.     obj.value = (obj.value).replace(/^\s+/, '').replace(/\s+$/, '');
  12.     }
  13.  
  14.  
  15.   if(document.personal.person_name.value=='')
  16.  {
  17.    document.personal.person_name.value='Enter Name';
  18.   document.personal.person_name.className='blurField';
  19.  // document.personal.person_name.focus();
  20.   //document.personal.person_name.select();
  21.     return true;
  22.   }
  23.   else
  24.         //document.personal.person_name.focus();
  25.   return false;
  26. }
  27.  
  28. function Climit()
  29.  
  30.  { var find=/[0-9\*\=\_\>\<\:\@\&\%\?\$\)\(\`\~\#\^\|\+\.\,\;\\\}\{\]\[\\"\!\/\-\']/;
  31.    var maxchars=25;
  32.  
  33.  if(document.personal.person_name.value.length > maxchars) 
  34.  {
  35.    alert('Too much data in the text box! Please remove '+
  36.     (document.personal.person_name.value.length - maxchars)+ ' characters');
  37.              document.personal.person_name.focus();
  38.             document.personal.person_name.select();
  39.    return false;
  40.     }
  41.  
  42.  
  43.  else if(document.personal.person_name.value.search(find)!= -1)
  44.         {
  45.             alert("Only letters are allowed.");
  46.             document.personal.person_name.focus();
  47.             document.personal.person_name.select();
  48.             return false;
  49.         }
  50.         else
  51.    return true; 
  52.  }
  53.  
  54. </script>
  55.  
  56.  
Expand|Select|Wrap|Line Numbers
  1.  
  2.   </tr>
  3.   <tr>
  4.     <td><div align="left"><span class="style30">*&nbsp;</span><span class="style26">Contact No </span></div></td>
  5.     <td align="left"><input type="text" cols="10" name="TelCC" maxlength="3" class="focusField" value="<?php echo $_POST['TelCC'];?>"style="width:24px;" >
  6.     -
  7.     <input type="text" cols="10" name="TelAC" maxlength="4" class="focusField" value="<?php echo $_POST['TelAC'];?>" style="width:27px;" >
  8.     -
  9.     <input type="text" cols="10" name="TelNo" maxlength="12" class="" value="<?php echo $_POST['TelNo'];?>" style="width:90px;" onChange="return cont();" ><div class="style3"><?php echo $duplicate_c ; ?></div>
  10.      <script language="javascript">
  11. function cont()
  12. {         
  13.      var find=/[a-zA-Z\`\~\!\@\#\$\%\^\&\*\(\)\-\_\=\+\[\]\{\}\|\\\ \:\;\'\"\<\,\>\.\/\?]/;
  14.  
  15.    if(document.personal.TelNo.value!="")
  16.     {
  17.            if(document.personal.TelCC.value.search(find)!= -1)
  18.                    {
  19.                             alert("Country code is not valid.");
  20.                             document.personal.TelCC.focus();
  21.                             document.personal.TelCC.select();
  22.                             return false;
  23.                    }
  24.  
  25.                 if(document.personal.TelAC.value.search(find)!= -1)
  26.                    {
  27.                             alert("Area code is not valid.");
  28.                             document.personal.TelAC.focus();
  29.                             document.personal.TelAC.select();
  30.                             return false;
  31.                    }           
  32.            if(document.personal.TelNo.value.length < 5) 
  33.                 {
  34.                 alert('Too short data in the text box! Please Insert '+
  35.                 (5-document.personal.TelNo.value.length )+ ' Digits');
  36.                 return false;
  37.                 }
  38.  
  39.     // var iChar="+-";
  40.  
  41.             //alert (i);
  42.                 if(document.personal.TelNo.value.search(find)!= -1)
  43.                    {
  44.                             alert("Only DIGITS are allowed.");
  45.                             document.personal.TelNo.focus();
  46.                             document.personal.TelNo.select();
  47.                             return false;
  48.                    }        
  49.         re = /[0-9]/;
  50.       if(!re.test(document.personal.TelNo.value)) 
  51.       {
  52.         alert("Error: Phone number must contain at least one number (0-9)!");
  53.         document.personal.TelNo.focus();
  54.         return false;      
  55.       }
  56.                 //if (iChar.indexOf(document.personal.s_address.value.charAt(i))== -1) 
  57.       var ichar="+-";
  58.      var num=0;
  59.      //var arr= new array[];
  60.  
  61.       for (var i = 0; i < document.personal.TelNo.value.length; i++)
  62.        {
  63.            if(ichar.indexOf(document.personal.TelNo.value.charAt(i))!= -1)
  64.                 {
  65.                     num=num+1;
  66.  
  67.                     //alert(num);
  68.                 }
  69.         }            
  70.                if(num>3)
  71.                {  
  72.                   alert ("You can't insert more than 3 special characters");
  73.                     document.personal.TelNo.focus();
  74.                     document.personal.TelNo.select();
  75.                         return false;
  76.  
  77.                }                     
  78.  
  79.       }  
  80.  
  81.  
  82.     }     
  83.  
  84.       </script>    </td>
  85.   </tr>
  86.   <tr>
  87.     <td><div align="left"><span class="style26">&nbsp;&nbsp;Alternative Contact </span></div></td>
  88.     <td align="left"><input type="text" cols="10" name="ATelCC" maxlength="3" class="focusField" value="<?php echo $_POST['ATelCC'];?>"style="width:24px;">
  89.     -
  90.     <input type="text" cols="10" name="ATelAC" maxlength="4" class="focusField" value="<?php echo $_POST['ATelAC'];?>" style="width:27px;">
  91.     -
  92.     <input type="text" cols="10" name="ATelNo" maxlength="12" class="" value="<?php echo $_POST['ATelNo'];?>"style="width:90px;" onChange="return acont();">
  93.     <script language="javascript">
  94. function acont()
  95. {         
  96.      var find=/[a-zA-Z\`\~\!\@\#\$\%\^\&\*\(\)\-\_\=\+\[\]\{\}\|\\\ \:\;\'\"\<\,\>\.\/\?]/;
  97.  
  98.    if(document.personal.ATelNo.value!="")
  99.     {
  100.            if(document.personal.ATelCC.value.search(find)!= -1)
  101.                    {
  102.                             alert("Country code is not valid.");
  103.                             document.personal.ATelCC.focus();
  104.                             document.personal.ATelCC.select();
  105.                             return false;
  106.                    }
  107.  
  108.                 if(document.personal.ATelAC.value.search(find)!= -1)
  109.                    {
  110.                             alert("Area code is not valid.");
  111.                             document.personal.ATelAC.focus();
  112.                             document.personal.ATelAC.select();
  113.                             return false;
  114.                    }           
  115.            if(document.personal.ATelNo.value.length < 5) 
  116.                 {
  117.                 alert('Too short data in the text box! Please Insert '+
  118.                 (5-document.personal.ATelNo.value.length )+ ' digits');
  119.                 return false;
  120.                 }
  121.  
  122.     // var iChar="+-";
  123.  
  124.             //alert (i);
  125.                 if(document.personal.ATelNo.value.search(find)!= -1)
  126.                    {
  127.                             alert("Only DIGITS are allowed.");
  128.                             document.personal.ATelNo.focus();
  129.                             document.personal.ATelNo.select();
  130.                             return false;
  131.                    }    
  132.  
  133.  
  134.         re = /[0-9]/;
  135.       if(!re.test(document.personal.ATelNo.value)) 
  136.       {
  137.         alert("Error: Phone number must contain at least one number (0-9)!");
  138.         document.personal.ATelNo.focus();
  139.         return false;      
  140.       }
  141.                 //if (iChar.indexOf(document.personal.s_address.value.charAt(i))== -1) 
  142.       var ichar="+-";
  143.      var num=0;
  144.      //var arr= new array[];
  145.  
  146.       for (var i = 0; i < document.personal.ATelNo.value.length; i++)
  147.        {
  148.            if(ichar.indexOf(document.personal.ATelNo.value.charAt(i))!= -1)
  149.                 {
  150.                     num=num+1;
  151.  
  152.                     //alert(num);
  153.                 }
  154.         }            
  155.                if(num>3)
  156.                {  
  157.                   alert ("You can't insert more than 3 special characters");
  158.                     document.personal.ATelNo.focus();
  159.                     document.personal.ATelNo.select();
  160.                         return false;
  161.  
  162.                }                     
  163.  
  164.  
  165.       }  
  166.  
  167.  
  168.     }     
  169.  
  170.       </script>    </td>
  171.   </tr>
  172.   <tr>
  173.     <td><div align="left"><span class="style26">&nbsp;&nbsp;Email-Id</span></div></td>
  174.     <td align="left"><input name="email_Id" type="text" id="email_Id" onchange="javascript:return email('personal','email_Id');">
  175.     <script language="javascript">
  176.  
  177.     function email(personal,email_Id) {
  178.  
  179.  var reg = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[A-Za-z]{2,6})$/;
  180.    var address = document.forms[personal].elements[email_Id].value;
  181.    if(reg.test(address) == false) {
  182.       alert('Invalid Email Address');
  183.       return false;
  184.    }
  185. }
  186. </script>    </td>
  187.   </tr>
  188.   <tr>
  189.     <td><div align="left"><span class="style30">*&nbsp;</span><span class="style26">Designation</span></div></td>
  190.               <td align="left">&nbsp; </td>
  191.     <script language="javascript">
  192.  
  193. function desig()
  194.  
  195.  { 
  196.      obj = document.getElementById('designation');
  197.     obj.value = (obj.value).replace(/^\s+/, '').replace(/\s+$/, '');
  198.  
  199.  var find=/[0-9\*\=\_\>\<\:\@\&\%\?\$\`\~\#\^\|\+\.\,\;\\\}\{\]\[\\"\!\/\']/;
  200.  
  201.   if(document.personal.designation.value.search(find)!= -1)
  202.         {
  203.             alert("Only letters are allowed.")
  204.             setTimeout("document.personal.designation.focus()",1);
  205.             //document.personal.designation.select();
  206.             setTimeout("document.personal.designation.select()",1);
  207.             return false;
  208.         }
  209.         else
  210.    return true; 
  211.  }
  212.  
  213.     </script>
  214.   </tr>
  215.  
  216.   <tr>
  217.     <td><div align="left"><span class="style30">*&nbsp;</span><span class="style26">Address</span></div></td>
  218.     <td align="left"><span class="style11">
  219.       <textarea name="address" rows="3" id="address" cols="35" onchange="return cadress();"></textarea>
  220.     </span></td>
  221.     <script language="javascript">
  222. function cadress()
  223.  {         
  224.            var find=/[~\`\!\$\%\^\|\\\{\}\?\<\>\[\]\"\'\_\+]/;
  225.           var maxchar=100;
  226.           {
  227.     obj = document.getElementById('address');
  228.  
  229.     obj.value = (obj.value).replace(/^\s+/, '').replace(/\s+$/, '');
  230.     }
  231.           if(document.personal.address.value!="")
  232.            {
  233.            if(document.personal.address.value.length > maxchar) 
  234.                 {
  235.                 alert('Too much data in the text box! Please remove '+
  236.                 (document.personal.address.value.length - maxchar)+ ' characters');
  237.                 return false;
  238.                 }
  239.  
  240.  
  241.                           else if(document.personal.address.value.search(find)!= -1)
  242.                                   {
  243.                                     alert("Only letters are allowed.");
  244.                                         document.personal.address.focus();
  245.                                         document.personal.address.select();
  246.                                         return false;
  247.                                   }
  248.  
  249.                             else
  250.                         {
  251.                         return true;
  252.                         }
  253.  
  254.  
  255.          }     
  256.  
  257.      }
  258.  
  259.      </script>
  260.   </tr>
  261.   <tr>
  262.     <td><div align="left"><span class="style30">*&nbsp;</span><span class="style26">Country</span></div></td>
  263.     <td align="left"><select name="country" style="color:#000000; border: 1 solid #000000"  id="country" >
  264.                               <option value="">-------SELECT--------</option>
  265.             <?php        
  266.             $all_country = mysql_query("SELECT country from country") or die('Error :' . mysql_error());
  267.  
  268.             while($country_val = mysql_fetch_array($all_country))
  269.                 {
  270.  
  271.                     ?>
  272.                               <option value="<?php echo $country_val['country'];?>" <?php echo($_POST['country']==$country_val['country']?'selected':'')?>><?php echo $country_val['country'];?></option>
  273.                               <?php
  274.  
  275.                                  }
  276.                 ?>
  277.                             </select></td>
  278.   </tr>
  279.   <tr>
  280.     <td><div align="left"><span class="style26">&nbsp;&nbsp;Zip Code</span></div></td>
  281.     <td align="left"><input name="zipcode" type="text" id="zipcode" onchange="return zipnumb();">
  282.     <script language="javascript">
  283.   function zipnumb()
  284. {
  285.     var num;
  286.     num=document.personal.zipcode.value;
  287.     var find=/[a-zA-Z\*\ \=\_\>\<\:\@\&\%\?\$\)\(\|\~\`\!\#\^\]\[\}\{\,\.\;\'\"\+\-\\\/]/;
  288.     if (num.search(find)!= -1)
  289.         {
  290.             alert("That is not a valid zipcode Please enter again.");
  291.             document.personal.zipcode.focus();
  292.             document.personal.zipcode.select();
  293.             return false;
  294.         }
  295. else if(document.personal.zipcode.value.length > 15 ||document.personal.zipcode.value.length < 5) 
  296.                 {
  297.                 alert("It cannot be more than 15 digit and less than 5 digit");
  298.                 document.personal.zipcode.focus();
  299.                 document.personal.zipcode.select();
  300.                 return false;
  301.                 }
  302.                 else
  303.  
  304.             return true;
  305.  
  306.  
  307. }
  308. </script>  
  309.   <span class="style33">&nbsp;(e.g. 100001)</span></td>
  310. </tr>
  311.   <tr>
  312.     <td><div align="left"><span class="style26">&nbsp;&nbsp;Photo</span></div></td>
  313.     <td align="left"><input name="photo" type="file"></td>
  314.   </tr>
  315.   <tr>
  316.     <td><div align="left"><span class="style30">*&nbsp;</span><span class="style26">Details</span></div></td>
  317.     <td align="left"><span class="style11">
  318.       <textarea name="other_details"  id="other_details" rows="9" cols="37" onchange="return gap();"></textarea>
  319.     </span>
  320.  
  321.       <script language="javascript">
  322.       function gap()
  323.      {
  324.     obj = document.getElementById('other_details');
  325.  
  326.     obj.value = (obj.value).replace(/^\s+/, '').replace(/\s+$/, '');
  327.     }
  328.     </script>    </td>
  329.   </tr>
  330.   <tr>
  331.   <td><div align="center"><span class="style16"></span></div></td>
  332.   <td><span class="style13">
  333.     <input type="submit" name="submit" value="Insert">
  334.     <input type="reset" nmae="reset" value="Reset">
  335.   </span></td>
  336.   </tr>
  337. </form>
  338. </table>
  339.  </fieldset>
  340. </td>
  341.               </tr>
  342.           </table>
  343.       </td>
  344.  
  345. <!-- End ImageReady Slices -->
  346. </body>
  347. </html>
  348.  
Jul 2 '08 #11

acoder
Expert Mod 15k+
P: 16,027
Thanks for using code tags. Unfortunately, you used the wrong type. Check the reply guidelines on the right-hand side to see how they should look, or use the # button which should wrap your code using the proper tags.
Jul 2 '08 #12

acoder
Expert Mod 15k+
P: 16,027
Try increasing the timeout, e.g.
Expand|Select|Wrap|Line Numbers
  1. setTimeout(function() {document.personal.person_name.focus();},50);
  2. setTimeout(function() {document.personal.person_name.select();},50);
Jul 2 '08 #13

P: 10
Hi,
Thanks again for ur reply.

Hi,
I have tried the setTimeout function but what happened in Mozilla, it selects the text box value after showing error message but mouse cursor can be moved to the next field which is not occuring in IE.

Thanks & Regards,

Sourav
Jul 4 '08 #14

acoder
Expert Mod 15k+
P: 16,027
The probable reason for that is that the onchange doesn't fire the next time because nothing has changed, so you could use onblur. However, it's much better to highlight the field and put a message next to the field using the DOM rather than using alerts onblur (which can sometimes fire unexpectedly).
Jul 4 '08 #15

Post your reply

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