4 Replies Latest reply on Apr 18, 2006 6:51 AM by marceldeboer

    if else statment in mailform

    marceldeboer
      I have been creating a mail form with different field options like "Input Fields", "Combo Boxes and "Checkboxes". Some of the fields are required. When the person is pressing the next button the required fields will be checked with a if statement, this is working fine until I have added the else statement at the end of my action script.
      Below is my action script code to check the fields and if they are correct to send it to php. I hope someone can help me out here.
      It looks like the else statement skips the if statment.
      Some field descriptions and “setresult” field are in Dutch.

        • 1. if else statment in mailform
          blemmo Level 1
          The 'else' is only associated with the last if statement, so it will always kick in when the last condition is false. To have it executed when none of the above conditions is met, add an 'else' before every 'if', so that they are connected:
          if (condition 1) {...}
          else if (condition 2) {...}
          ...
          else { send form }

          cheers,
          blemmo
          • 2. Re: if else statment in mailform
            marceldeboer Level 1
            Ok, I have added the else if statement to all if's. It is working but not totaly as I want to.
            Because when you press the next button I want all the required fields (that are not filled in) to become yellow, in this case senario only the first required field, that is not filled in, becomes yellow and the other fields are white and not yellow. Is there a way to solve this problem.
            • 3. Re: if else statment in mailform
              blemmo Level 1
              I see... in that case, it's better to use a variable to indicate if the data should be sent or not. If something is missing, set this var to false, and before sending, check for its value:
              --
              on (release) {
              var senddata = true;
              if (condition 1){ ...; senddata = false; }
              if (condition 2){ ...; senddata = false; }
              ...
              if (senddata) { send to server };
              --
              So when no field is missing, senddata would be true, and the mail can be sent. If one or more fields are missing, it's set to false, and the last 'if' will fail, so it's not sent.

              cheers,
              blemmo
              • 4. Re: if else statment in mailform
                marceldeboer Level 1
                OK, I have added your solution. It's working fine as I want to.

                Thank you for your support blemmo