Skip to content

Instantly share code, notes, and snippets.

@brentonashworth
Created September 23, 2010 21:11
Show Gist options
  • Save brentonashworth/594373 to your computer and use it in GitHub Desktop.
Save brentonashworth/594373 to your computer and use it in GitHub Desktop.
$(function() {
$("#hire-date").datepicker({dateFormat: 'yy-mm-dd'});
$("#language").autocomplete({source: "langs-starting-with"});
$("#name").blur(function() {
validateField("name");
});
$("#language").focus(function() {
validateField("hire-date");
});
$("#language").blur(function() {
validateField("language");
});
});
function validateField(id) {
var value = $("#" + id).val();
$.getJSON("validate?" + id + "=" + value, function(data){
if(data != null) {
var errorId = "#" + id + "-error";
if(data.status == "fail" && data.errors && data.errors[id]) {
var errorMessage = data.errors[id] [0];
$(errorId).html(errorMessage);
$(errorId).show();
}
else {
$(errorId).html("");
$(errorId).hide();
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment