ik heb een javascriptje geschreven wat moet controleren of een gebruikersnaam al bestaat (ajax).
Nu ben ik zover dat het werkt. Maar het gekke is dat het alleen werkt met een test-alert. Zodra ik deze alert verwijder, werkt het helemaal niet meer.
Misschien iemand een oplossing?
<script>
function validateFormStep1() {
var usertype;
for( i = 0; i < document.registration.usertype.length; i++ ) {
if(document.registration.usertype[i].checked) {usertype = document.registration.usertype[i].value; break;}
}
//var usertype = document.forms["registration"]["usertype"].checked.value;
var username = document.forms["registration"]["login-name"].value;
var usermail = document.forms["registration"]["e-mail"].value;
var password = document.forms["registration"]["password"].value;
var message = "";
//----------------------------------------------------------------------------------------------------------------
//Check if username already exists.
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if (xmlhttp.responseText == "true")
{
message = message + username + " already exists.\n";
//alert(message);
//return false;
}
} //else {alert("status " + xmlhttp.readyState + " http status" + xmlhttp.status);}
}
xmlhttp.open("GET","checkuser.ajax.php?username="+username,true);
xmlhttp.send();
alert("Zodra ik dit weghaal werkt het niet meer");
//Pause
//------------------------------------------------------------------------------------------------
//Username criteria (mandatory).
if (username.length == 0) {message = message + "Login-name is a mandatory field.\n";} //Mark this line to make field optional.
if (username.length != 0) {
if (
!(username.match(/^[0-9a-zA-Z]+$/)) || //Only these characters allowed.
false) {message = message + username + " is not a valid name.\n";}
}
//-------------------------------------------------------------------------------------------------
//E-mail criteria (mandatory).
if (usermail.length == 0) {message = message + "Email is a mandatory field.\n";} //Mark this line to make field optional.
if (usermail.length != 0) {
var apepos = usermail.indexOf ('@',1); //Position of the first apetail and apetail cannot be 1st position.
var dotpos = usermail.lastIndexOf ('.'); //Position of the last dot.
var apenum = (usermail.match(/@/g)||[]).length; //Count apetails.
if (
!(usermail.match(/^[0-9a-zA-Z\&\@\.\-]+$/)) || //Only these characters allowed.
apepos == -1 || //Apetail MUST be present.
dotpos == -1 || //Dot MUST be present.
apenum != 1 || //Apetail must be present only once.
apepos>dotpos || //Apetail may not be after last dot.
usermail.charAt(0) == '.' || //First character may not be a dot.
usermail.charAt(usermail.length-1) == '.' || //Last character may not be a dot.
usermail.charAt(apepos+1) == '.' || //First character after apetail may not be a dot.
usermail.charAt(apepos-1) == '.' || //Last character before the apetail may not be a dot.
false) {message = message + usermail + " is not a valid e-mail address.\n";}
}
//-----------------------------------------------------------------------------------------------------
//Password criteria (mandatory).
if (password.length == 0) {message = message + "Password is a mandatory field.\n";} //Mark this line to make field optional.
if (password.length != 0) {
if (
!(password.match(/^[0-9a-zA-Z]+$/)) || //Only these characters allowed.
password.length < 6 || //Length must be at least 6 characters.
false) {message = message + "Password must be at least 6 characters long and may contain only letters or numbers.\n";}
}
//----------------------------------------------------------------------------------------------------
//Display alert message on screen when one or more field does not match criteria.
if (message.length > 0) {
alert(message);
return false;
} else {
//alert(usertype + "Check succesfull\n");
document.getElementById('step1').style.display = 'none';
document.getElementById('step2').style.display = 'inline';
return true;
}
}
</script>