10 Replies Latest reply on Feb 13, 2007 9:07 AM by Dave Blake

    If - Else error

    Dave Blake Level 1
      I am trying to set up a form in flash that will email the entered data in the fields. I have the email part functioning correctly. My problem is getting the error message when the user does not fill in a field.

      Here is my code on my submit button:
      on (release) {
      if (txtName ne "" && txtFrom ne "" && txtMessage ne "") {
      loadVariablesNum("cdontsMail.asp", 0, "POST");
      gotoAndPlay("valid");
      } else {
      gotoAndPlay("invalid");
      }
      }

      If I type in a 1 or any character between the quotes, it realized that and sends an error. For instance, if I coded : if (txtName ne "1"... and typed in a 1 in the txtName field, it would come back as invalid. For some reason, it doesn't realize "" to mean an empty field. What am I doing wrong here????

      Dave
        • 1. Re: If - Else error
          kglad Adobe Community Professional & MVP
          you should use != instead of ne and you should use your textfield's text property (or htmlText property) instead of a variable name.

          but the main problem may be that your textfield is not empty even though it may appear to be so to you. if you're kerning your textfield or it's html enabled it may not be empty.
          • 2. Re: If - Else error
            Dave Blake Level 1
            Ok, I did change the ne to != but that didn't solve the problem. In testing, if I run the swf file and enter data into the fields and enter and then go back to the form which still contains the data and highlight and delete it, it then gives me the error message- it then sees the field as empty. Why does it initially see the field as having something in it?
            • 3. Re: If - Else error
              kglad Adobe Community Professional & MVP
              use trace(txtName+" "+txtName.length) to start the process to find what flash sees assigned to txtName before you enter anything in your textfield.
              • 4. If - Else error
                Sketchsta Level 1
                Check your publish settings, there was a guy with almost the same problem. He had Flash 5 code, and publishing on Flash 8.. you might be doing the opposite..

                or you can try:
                on (release) {
                if (txtName.text != "" && txtFrom.text != "" && txtMessage.text != "") {
                loadVariablesNum("cdontsMail.asp", 0, "POST");
                gotoAndPlay("valid");
                } else {
                gotoAndPlay("invalid");
                }
                }

                I think this is what kglad suggested you try...
                • 5. Re: If - Else error
                  Dave Blake Level 1
                  I am working in FlashMX 2004, so I'm not sure if that has this option. But here's the code I added:
                  on (release) {
                  trace(txtName+" "+txtName.length);
                  if (txtName != "" && txtFrom != "" && txtMessage != "") {
                  loadVariablesNum("cdontsMail.asp", 0, "POST");
                  gotoAndPlay("invalid");
                  } else {
                  gotoAndPlay("valid");
                  }
                  }

                  When I play the file and hit submit without entering anything, it gives me this:
                  _level0.txtName 0

                  Dave
                  • 6. Re: If - Else error
                    Dave Blake Level 1
                    Hey!! I used the code Sketchsta suggested and it works! AMEN!! Thanks guys for all your suggestions and help!!!!!!

                    Dave
                    • 7. Re: If - Else error
                      Dave Blake Level 1
                      One more quick question- if I leave a field empty and hit submit, it gives me the error screen message which has a "go back button" to that enter field. However, all input info from the previous attempt is gone and the user has to start over. Is there any way to keep what text was entered the first time?
                      • 8. Re: If - Else error
                        kglad Adobe Community Professional & MVP
                        your previous issue was caused by using a textfield instance name and associated variable that were the same.

                        you must have some code somewhere that's causing your textfield to clear its text property after your button is pressed. or maybe you're using a component?
                        • 9. Re: If - Else error
                          Sketchsta Level 1
                          i would clear if the form is being loaded into the main SWF...

                          is that what you are doing Dave Blake?
                          • 10. Re: If - Else error
                            Dave Blake Level 1
                            The contact form is actually a seperate scene in the swf file. I tried importing the form as a swf into the file but then all my buttons, etc, lose their functionality.