Hi,
I have set up all my fields to validate with php and ajax using the jquery library.
The php array returned is
$response = array(
'ok' => true or false,
'msg' => "message about ok or why failed"
);
The is correctly printed next to the corresponding input box. Now i would to check to make sure that they all returned ok = true when the form is submitted. However i am new to javacript and ajax and dont know where to begin.
javascript function
Code:
var validateUsername = $('#validateUsername');
$('#username').keyup(function () {
var t = this;
if (this.value != this.lastValue) {
if (this.timer) clearTimeout(this.timer);
validateUsername.removeClass('error').html('<img src="../images/ajax-loader.gif" height="16" width="16" /> checking username availability...');
this.timer = setTimeout(function () {
$.ajax({
url: '../scripts/validatefunctions.php',
data: 'action=check_username&username=' + t.value,
dataType: 'json',
type: 'post',
success: function (j) {
validateUsername.html(j.msg);
}
});
}, 200);
this.lastValue = this.value;
}
});
html
Code:
<div>
<label for="username">Username, valid: a-z.-_</label>
<input type="text" name="username" value="" id="username" />
<span id="validateUsername"></span>
</div>
Thanks!