K, werkin on a lil’ form and the onKillFocus doesn’t want to work. Any ideas?
//POPULATE COUNTRY LIST
var countryList = new LoadVars();
countryList.load("../assets/countries.list");
countriesBox.addItem('','');
countryList.onLoad = function() {
var comboCountries = countryList.countries.split(",");
for (i=0; i<comboCountries.length; i++) {
countriesBox.addItem(comboCountries*,comboCountries*);
}
};
//CLEAR ALL FIELDS
for (i in this) {
if (this*.textWidth != undefined) {
this*.text = "";
}
}
//SUBMIT ACTION
next_but.onRelease = function() {
var error:Boolean = false;
if (username_txt.length<=5 && username_txt.text != "") {
error = true;
username_error_txt.text = "Must be at least 6 characters.";
} else {
username_error_txt.text = "";
}
if (username_txt.text == "") {
error = true;
username_error_txt.text = "Required.";
}
username_txt.onKillFocus = function(newFocus:Object) {
trace("killfocus");
if (!checkUsername(username_txt.text)) {
error = true;
username_error_txt.text = "Username is taken.";
}
};
if (password_txt.length<=5) {
error = true;
password_error_txt.text = "Must be at least 6 characters.";
} else {
password_error_txt.text = "";
}
if (password_txt.text == "") {
error = true;
password_error_txt.text = "Required.";
}
if (passwordConfirm_txt.text == "") {
error = true;
passwordConfirm_error_txt.text = "Required.";
} else {
passwordConfirm_error_txt.text = "";
}
if (password_txt.length>5 && passwordConfirm_txt.length>0) {
if (password_txt.text != passwordConfirm_txt.text) {
error = true;
passwordConfirm_error_txt.text = "Passwords do not match.";
}
}
if (email_txt.text == "") {
error = true;
email_error_txt.text = "Required.";
} else {
email_error_txt.text = "";
}
email_txt.onKillFocus = function(newFocus:Object) {
if (email_txt.length>0) {
if (!validateEmail(email_txt.text)) {
error = true;
email_error_txt.text = "Invalid email format e.g:(yourname@somesite.com)";
} else {
if (!checkEmail(email_txt.text)) {
error = true;
email_error_txt.text = "Email address taken, you must use a unique address.";
}
}
}
};
if (countriesBox.value == "") {
error = true;
countriesBox_error_txt.text = "Required.";
} else {
countriesBox_error_txt.text = "";
}
if (checkBox_mc._currentframe == 1) {
error = true;
checkBox_error_txt.text = "You must agree to the terms and Conditions to continue.";
} else {
checkBox_error_txt.text = "";
}
if (!error) {
trace("success");
}
};
//VALIDATION FUNCTIONS
function checkUsername(username:String) {
var checkUsername:LoadVars = new LoadVars();
checkUsername.username = username;
checkUsername.sendAndLoad("../php/checkUsername.php",checkUsername,"POST");
checkUsername.onLoad = function() {
if (checkUsername.result == "taken") {
return (false);
} else {
return (true);
}
};
}
function checkEmail(email:String) {
var checkEmail:LoadVars = new LoadVars();
checkEmail.Email = email;
checkEmail.sendAndLoad("../php/checkEmail.php",checkEmail,"POST");
checkEmail.onLoad = function() {
if (checkEmail.result == "taken") {
return (false);
} else {
return (true);
}
};
}
function validateEmail(email:String) {
if (email.length>=7) {
if (email.indexOf("@")>0) {
if ((email.indexOf("@")+2)<email.lastIndexOf(".")) {
if (email.lastIndexOf(".")<(email.length-2)) {
return (true);
}
}
}
}
return (false);
}
//MONKEY FARTS