double alert onBlur

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vauneen
    New Member
    • Sep 2006
    • 1

    double alert onBlur

    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
  • rameshsambu
    New Member
    • Oct 2006
    • 15

    #2
    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

    Code:
    <script language="JavaScript" type="text/javascript">
    
    var error1,error2,error3;
    		if(document.bloody_thing_1.value == "") {
    			error1 = "Enter a valid bloody_thing_1.\n";
    		} 
    		if(document.bloody_thing_2.value == "") {
    			error2 ="Enter a valid bloody_thing_2.\n";
    		} 
    		if(document.bloody_thing_3.value == "") {
    			error3 = "Enter a valid bloody_thing_3.\n";
    		} 
    	var error = "";
    	if(error1 != null) {
    		error = error + error1;
    		document.bloody_thing_1.value="";
    		document.bloody_thing_1.focus();
    	}
    	if(error2 != null) {
    		error = error + error2;
    		document.bloody_thing_2.value="";
    		document.bloody_thing_2.focus();
    	}
    	if(error3 != null) {
    		error = error + error3;
    		document.bloody_thing_3.value="";
    		document.bloody_thing_3.focus();
    	}
    	if(error != "") {
    		document.moneyform.total_monthly_income.value="";
    		alert("Following cool and sexy errors occured in your form submission. \n"+error);
    		return false;	
    	}
    	else {
    		return true;
    	}	
    
    
    </script>
    Please change the varible names and error messages as per your need

    Also willing to help more if needed.


    -Ramesh

    Comment

    Working...