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

double alert onBlur

P: 1
Hi,
I'm trying to find a work-around for a javascript issue i have.
i have a list of text input fields (created using asp) and onblur, i loop through all fields evaluating each one, making sure it contains only numbers, and place focus back on the incorrect field if the evaluation fails (and show an alert box).
the problem is, i evaluate as i leave a field (A) and enter the next (B), and so if the evaluation fails, my function is called for a second time (when my code leaves the B fields) and fails again, so the alert box is called 2 in short succession.
of course if i dont put focus on field A when it fails, i wouldnt had a problem but i'd prefer to show the user exactly where the error is.
any help appreciated....
Vauneen
Sep 14 '06 #1
Share this Question
Share on Google+
1 Reply


rameshsambu
P: 15
hi vauneen

I remember i had to go through a similar situation in my good old days.

I think what I did may be of some help to you

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2.  
  3. var error1,error2,error3;
  4.         if(document.bloody_thing_1.value == "") {
  5.             error1 = "Enter a valid bloody_thing_1.\n";
  6.         } 
  7.         if(document.bloody_thing_2.value == "") {
  8.             error2 ="Enter a valid bloody_thing_2.\n";
  9.         } 
  10.         if(document.bloody_thing_3.value == "") {
  11.             error3 = "Enter a valid bloody_thing_3.\n";
  12.         } 
  13.     var error = "";
  14.     if(error1 != null) {
  15.         error = error + error1;
  16.         document.bloody_thing_1.value="";
  17.         document.bloody_thing_1.focus();
  18.     }
  19.     if(error2 != null) {
  20.         error = error + error2;
  21.         document.bloody_thing_2.value="";
  22.         document.bloody_thing_2.focus();
  23.     }
  24.     if(error3 != null) {
  25.         error = error + error3;
  26.         document.bloody_thing_3.value="";
  27.         document.bloody_thing_3.focus();
  28.     }
  29.     if(error != "") {
  30.         document.moneyform.total_monthly_income.value="";
  31.         alert("Following cool and sexy errors occured in your form submission. \n"+error);
  32.         return false;    
  33.     }
  34.     else {
  35.         return true;
  36.     }    
  37.  
  38.  
  39. </script>
Please change the varible names and error messages as per your need

Also willing to help more if needed.


-Ramesh
Nov 2 '06 #2

Post your reply

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