Use jQuery.post() result in javascript function
Posted
by
Juvlius
on Stack Overflow
See other posts from Stack Overflow
or by Juvlius
Published on 2012-10-03T09:11:46Z
Indexed on
2012/10/03
9:37 UTC
Read the original article
Hit count: 127
JavaScript
|jQuery
I've got no clue how to do the following, so I wasn't sure what to search for either.
For validating my registration form I've a javascript function that checkes the existence of the inserted username in the database onblur of the username textfield.
function checkUsername(username){
$.post("checkmail.php", {mail: mailcheck} , function(data){
var $response=$(data);
var response = $response.filter('#mail-response').text();
if(response == "taken") {
document.getElementById('username').style.borderColor = rood;
valid = false;
}
});
}
This works fine, but now I want to validate it again onsubmit of the form in case users decide to submit an existing username.
function validateForm() {
var valid = true;
//checks different fields
//now check voor username existence
var username = document.getElementById('username').value;
checkUsername.call(username);
if (!valid) {
return false;
}
else {
return true;
}
}
I'm not familiar enough with Javascript to get this working. Probably thinking in the wrong direction...
© Stack Overflow or respective owner