View Full Version : Help with JS IF logic

07-30-2008, 02:59 PM
I need some help with JavaScript logic IF statements

I have a form that contains 5 text input fields (ITEM0 thru ITEM4 if you will).

If all 5 fields contain NOTHING when the users submits, the user needs to get a message requesting that they enter data in least 1 of the 5 fields. If any 1 of the 5 fields contain anything the form should go through.

Thanks in advance for your help.


Philip M
07-30-2008, 03:10 PM
for (var i = 0; i <= 4; i++) {
var val = document.formname.item+[i].value;
val = val.replace(/^\s+/,""); // strip leading spaces
if ( val != "") {
return true; // i.e. submit the form as at least one field is filled in
alert ("You must fill in at least one text input field");
return false;

07-30-2008, 03:21 PM
Thank you Phillip!