Attempting what would appear to be a simple pre ajax-post validation against a short form. This is working correctly and posting data perfectly until adding an attempt at a conditional value check against it.
JQuery is adding the values to the form on the fly until the user changes the values in the form fields and am checking against the default values since they will be added if the user leaves blank or default.
Thoughts were to (a)do a simple conditional for #tip and #num and THEN (b)ajax post if the condition was met. Was trying to keep this simple and not use additional plugins or code.
Am I missing the obvious, or going about the this wrong way?
function submitForm() {
if( ($('#tip').val() != 'Enter Tip')
AND ($('#num').val() != 'ID number') ) {
$.ajax({type:'POST', url:'populatedb.php', data:$('#TipForm').serialize(), success: function(response) {
$('.formresult').html(response);
$("#TipForm").hide();
}});
return false;
} else {
alert("Please fill all form fields");
}
} // end submitForm()
I think you need this line
instead of the following