Skip to content

Instantly share code, notes, and snippets.

@ideefixe
Created January 25, 2013 20:50
Show Gist options
  • Save ideefixe/4637727 to your computer and use it in GitHub Desktop.
Save ideefixe/4637727 to your computer and use it in GitHub Desktop.
Javascript Form Validation
function init() {
$('#general').on('submit', function(e) {
pass = true;
$('input, textarea', this).removeClass('error');
$('input, textarea', this).each(function() {
if ($(this).val() === '') {
$(this).addClass('error');
pass = false;
}
})
if (pass === true) {
$.ajax({
url : 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8',
type : 'post',
dataType : 'json',
data : $('#general').serialize(),
success : function(data) {
$('#general').html('<h4>Your message has been received.</h4> <p>Please expect a response within 24-48 hours.</p>')
}
});
}
return false;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment