Skip navigation
Currently Being Moderated

Checking a variable...

Oct 4, 2007 11:57 PM

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
 
Replies
  • Currently Being Moderated
    Oct 5, 2007 6:13 AM   in reply to Iron_Mike
    “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.
     
    |
    Mark as:
  • Currently Being Moderated
    Oct 5, 2007 7:36 AM   in reply to Iron_Mike
    you need to test for the length of text, not just length...

    _parent.form.name_input.text.length

    c
     
    |
    Mark as:
  • Currently Being Moderated
    Oct 5, 2007 9:04 AM   in reply to Iron_Mike
    Put a trace statement in the on() to see the value of the _name_input.text.length and message_input.text.length.
     
    |
    Mark as:
  • Currently Being Moderated
    Oct 5, 2007 12:13 PM   in reply to Iron_Mike
    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:

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points