Use jQuery.post() result in javascript function
<p>I've got no clue how to do the following, so I wasn't sure what to search for either.</p>

<p>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. </p>

<pre><code>function checkUsername(username){
$.post("checkmail.php", {username: username} , function(data){
var $response=$(data);
var response = $response.filter('#username-response').text();
if(response == "taken") {
    document.getElementById('username').style.borderColor = rood;
    valid = false;
}
});
</code></pre>

<p>}</p>

<p>This works fine, but now I want to validate it again onsubmit of the form in case users decide to submit an existing username.</p>

<pre><code>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;
    }
}
</code></pre>

<p>I'm not familiar enough with Javascript to get this working. Probably thinking in the wrong direction...</p>
