Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2008
    Posts
    37
    Thanks
    5
    Thanked 0 Times in 0 Posts

    multiple alerts poping up

    Hey guys. New to this forum. I am stuck with a problem and am here to get some help


    In the code below I have an alert message to pop up if someone enters a wrong character into the textfield. this works good except say the user enters 2 or more special characters then that is how many alert messages pop up. so the user would have to click ok 2 - 4 times or however many. in the code below can some one point me in the right direction to where I can change my code for just one pop up alert.

    Code:
    function ValidateData(form) {
    	var result = true;
    	var username = document.getElementsByName('username')[0];
    		var Chars = "abcdefghijklmnopqrstuvwxyz0123456789_.";
    		for (var i = 0; i < username.value.length; i++) {
    			if (Chars.indexOf(username.value.charAt(i)) == -1) {
    				alert("Invalid User Name.  User Name cannot contain spaces or special characters other than an underscore or period.");
    				result = false;
    			}
    		}
    	return result;
    }
    thanks for the help

  • #2
    New Coder
    Join Date
    Sep 2008
    Posts
    37
    Thanks
    5
    Thanked 0 Times in 0 Posts
    never mind I solved it

    I needed a beak; in the code. if anyone was wondering now the code looks like

    Code:
    function ValidateData(form) {
    	var result = true;
    	var username = document.getElementsByName('username')[0];
    	
    		var Chars = "abcdefghijklmnopqrstuvwxyz0123456789_.";
    		for (var i = 0; i < username.value.length; i++) {
    			if (Chars.indexOf(username.value.charAt(i)) == -1) {
    				alert("Invalid User Name.  User Name cannot contain spaces or special characters other than an underscore or period.");
    				result = false;
    				break;
    			}
    		}
    	return result;
    }
    Last edited by Mthor; 09-15-2008 at 09:17 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •