7 Replies Latest reply: Oct 5, 2007 1:28 PM by Iron_Mike RSS

    Checking a variable...

    Iron_Mike
      Hi,

      I've created a php email form which works fine, and I have action script attached on the 'submit' button which checks for certain values in the input fields..

      There are only 3 input fields:

      1. Name field - variable assigned = 'name_input' - Input text / single line
      2. email field - variable assigned = 'email' - Input text / single line
      3. Message field - variable assigned = 'message_input' - Input text / multi line

      All input text field are located in a movieclip called 'form'.

      Now, on the send button i check if certain criteria is met...

      Code:

      on(release){
      if ((_parent.form.name_input.length<1) or (_parent.form.message_input.length<1)) {
      _parent.error_message.gotoAndPlay("s1");
      }
      else{
      _parent.form.loadVariables("email.php", "POST");
      }
      }

      --> I cut this code down a little bit because the rest of the code works but those two conditions are just not checked by flash...

      Even if I leave both the Name and Message field empty it will still send the message and not (as it should) go and play the error message...

      I also already tried to replace the 'or' with '||' but still a no go...

      What am I doing wrong here ?

      As always, thanx for your help and advise in advance !

      Mike
        • 1. Re: Checking a variable...
          injpix Community Member
          “Even if I leave both the Name and Message field empty it will still send the message and not (as it should) go and play the error message...”

          Well that makes sense IF it cant find the form movieclip. If it cant find the movieclip, regardless if you have a value in the textfield or not, it will return ‘undefined’. So in your example it will look like this;

          on(release){
          if ((undefined<1) or (undefined <1)) {
          _parent.error_message.gotoAndPlay("s1");
          }
          else{
          _parent.form.loadVariables("email.php", "POST");
          }
          }

          Since ‘undefined’ is not a number, it will execute the code in the else statement.
          • 2. Re: Checking a variable...
            C-Rock Community Member
            you need to test for the length of text, not just length...

            _parent.form.name_input.text.length

            c
            • 3. Re: Checking a variable...
              Iron_Mike Community Member
              quote:

              Originally posted by: myIP
              “Even if I leave both the Name and Message field empty it will still send the message and not (as it should) go and play the error message...”

              Well that makes sense IF it cant find the form movieclip. If it cant find the movieclip, regardless if you have a value in the textfield or not, it will return ‘undefined’. So in your example it will look like this;

              on(release){
              if ((undefined<1) or (undefined <1)) {
              _parent.error_message.gotoAndPlay("s1");
              }
              else{
              _parent.form.loadVariables("email.php", "POST");
              }
              }

              Since ‘undefined’ is not a number, it will execute the code in the else statement.



              It can find the 'form' movieclip because the other variable I'm testing (besides the two mentioned) in that 'if' statement is also located in that 'form' movieclip and those conditions are perfectly checked - it's the same path.... that's what's so weird !!!!
              • 4. Re: Checking a variable...
                injpix Community Member
                Put a trace statement in the on() to see the value of the _name_input.text.length and message_input.text.length.
                • 5. Re: Checking a variable...
                  Iron_Mike Community Member
                  alright,

                  i traced both just the variable and then also the 'text length' of the variable with this code:

                  trace ("name input characters = " + _parent.form.name_input.length);
                  trace ("message input characters = " + _parent.form.message_input.length);
                  trace (_parent.form.name_input.text.length);
                  trace (_parent.form.message_input.text.length);

                  OUTPUT:

                  name input characters = 5
                  message input characters = 10
                  undefined
                  undefined

                  --> it can't trace the text length but it can trace just the variable...

                  Now, this was weird for me from the beginning because I have another variable in the code which is 'email' and I check that variable for it's length being <6 or not - because there can't be an email address with less than six characters total

                  AS for that:

                  (_parent.form.email.length<6)

                  --> this works perfectly, so I don't understand why those other two conditions are not checked especially because they are traced !!

                  Thanx again for your help !!

                  Mike

                  • 6. Re: Checking a variable...
                    clbeech Community Member
                    yeah, 'length' is a property of the textField just like 'text' is, you don't check the length of the 'text' property, you check the 'length' of the character array of the textField instance.

                    it might be a path issue or you could try something a little different, like:

                    • 7. Re: Checking a variable...
                      Iron_Mike Community Member
                      clbeech,

                      I tested '_parent.form.name_input == 0' which didn't work. then I tested (like u suggested)

                      _parent.form.name_input == null --> which works !

                      Thanx again to everybody for your input and help !!!

                      Mike