Skip to main content
Inspiring
April 18, 2006
Answered

if else statment in mailform

  • April 18, 2006
  • 4 replies
  • 447 views
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.

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer blemmo
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 replies

Inspiring
April 18, 2006
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
Inspiring
April 18, 2006
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.
blemmoCorrect answer
Inspiring
April 18, 2006
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