...

View Full Version : multiple alerts poping up



Mthor
09-15-2008, 08:59 PM
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.


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

Mthor
09-15-2008, 10:01 PM
never mind I solved it

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


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;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum