I am new to jquery and javascript but I wondered if anyone had any nice ideas about how I can show the user an error (alert) if they try to submit the form when both fields are empty.
Here is the code I am working with: http://jsfiddle.net/spadez/uaZkV/1/
I believe the relevant bit of the code is here:
$('#searchform').on('submit', function (event) {
var form = this;
event.preventDefault(); // stop the submission
processLocation(function (success) {
if (success) { // if the geocoding succeeded, submit the form
form.submit()
}
});
In sudo code I'm after something like this:
If #kw & #loc == 0
then alert "Cannot leave fields blank"
if( $(this).find('.class-of-input1').val() == '' )