I have the following code:
HTML
<input name="FirstName" id="FirstName" class="cat_textbox" maxlength="255" type="text" placeholder="First Name*">
<input name="LastName" id="LastName" class="cat_textbox" maxlength="255" type="text" placeholder="Last Name*">
<input name="EmailAddress" id="EmailAddress" class="cat_textbox" maxlength="255" type="text" placeholder="E-Mail Address*">
JS
$( ".prep-form" ).on( "click", function() {
var name = $.trim($('#FirstName').val()),
nachName = $.trim($('#LastName').val()),
eMail = $.trim($('#EmailAddress').val());
if (name == '' || nachName == '' || eMail == '') {
// SHOW ERROR MESSAGE
} else if //Continue with script -- Note: The script works fine until I add the above code...
return false;
});
As you can see I am checking three input fields to see if they are empty. If any of the three are empty I show an error message, otherwise the script should continue to run.
When I try the above code, regardless of what is in the input fields, the script will only show the error message.
What is wrong?
If any of the three are empty I show an error message. Shouldn't there be anORcondition?if (name || nachName || eMail ) {// valid } else { throw error }name.length === 0 || ...also: don't use 'trim' against a jQuery-Object (see Mukesh Kalgude's answer).