JavaScript help: abort submission if all fields aren't entered

JP-ODU
Tera Guru

I cribbed this section of JS, but it only puts up an alert message, while still submitting an empty form. How do I add an abort action to this?

if(user == '' || user == 'undefined' || user == 'null' || desc == 'null' || desc == '' || desc == 'undefined'|| contact == 'null' | contact == ' ' || contact == 'undefined'){
alert('Please enter your name, contact information, and a description of your issue before submitting.');
return;
}

I've tried the following without success. What am I doing wrong?

if(user == '' || user == 'undefined' || user == 'null' || desc == 'null' || desc == '' || desc == 'undefined'|| contact == 'null' | contact == ' ' || contact == 'undefined'){
alert('Please enter your name, contact information, and a description of your issue before submitting.');
return false;
}
if(user == '' || user == 'undefined' || user == 'null' || desc == 'null' || desc == '' || desc == 'undefined'|| contact == 'null' | contact == ' ' || contact == 'undefined'){
alert('Please enter your name, contact information, and a description of your issue before submitting.');
g_form.submitted = false;
return false;
}
1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@JP-ODU Please try the following and see if it works.

 

if(user == '' || user == 'undefined' || user == 'null' || desc == 'null' || desc == '' || desc == 'undefined'|| contact == 'null' || contact == ' ' || contact == 'undefined'){
alert('Please enter your name, contact information, and a description of your issue before submitting.');
return false;
}