Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help with JS IF logic

    I need some help with JavaScript logic IF statements

    Scope:
    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.

    Bren

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,253
    Thanks
    203
    Thanked 2,557 Times in 2,535 Posts
    Code:
    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;

  • #3
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you Phillip!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •