Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking a variable...

Status
Not open for further replies.

michanagel

Technical User
Jun 23, 2007
34
US
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...

What am I doing wrong here ?

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

Mike
 
Kenneth,

doesn't make any sense to me, I check about 20 other conditions for another variable (email) before that always with the 'or' and not with the '||' and those work just great, but those last two conditions just won't get checked...

Anyways, I tried it and unfortunately a no go... :(

Any other suggestions ?

Thanx for your help !!

Mike
 
or" is not part of ActionScript, or to be more precise it was in Flash 4 days but not any more. But I suppose it still works in AS1/2 so that it's backward compatible.

The same applies to the way you're assigning variables to TextFields. Never do that unless you're using Flash 4. Assign TextField.text to a variable instead.

Put [tt]trace(parent.form.name_input); [/tt] in the button script to see what you're getting.

Kenneth Kawamoto
 
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
 
Kenneth,

what do u mean ?

I shouldn't use variables for text fields ?

Well, I gave the text fields instance names as well and checked those and it still didn't work...

also, as mentioned there are three variables (email, name_input, message_input) and one (email) is doing fine regarding all those conditional checks and the the other two are not...

so there's still the question why that happens...
 
got it working,

I tested '_parent.form.name_input == 0' which didn't work. then I tested

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

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

Mike
 
Good call oldnewbie...

If it's working for you then that's fine but the proper way is to give TextField instance a name.
Code:
// "tfName" is the name of the name input TextField

if(!this._parent.form.tfName.text.length){
   trace("No name");
}else{
   this._parent.form.name_input = this._parent.form.tfName.text;
   // LoadVars etc.
}
If you're not convinced, here's the excerpt from Flash doc:
About text field instance and variable names
...
In the Var text box in the Property inspector, you can assign a variable name to a dynamic or input text field. You can then assign values to the variable. This is a deprecated functionality that you might use when you create applications for older versions of Flash Player (such as Flash Player 4). When you target newer players, target the text of a text field by using its instance name and ActionScript.

Do not confuse a text field's instance name with its variable name, however. A text field's variable name is a variable reference to the text contained by that text field; it is not a reference to an object.
This is the exact confusion you have fall into! (Unless you're on Flash 4)

Kenneth Kawamoto
 
Kenneth,

I did not fall into that confusion, because if you read my post(s) carefully I stated twice that there are 3 variables.

--> email, name_input, message_input

The first one ('email') is checked 20 times (with all kind of conditions) and it all works - it is also checked with this condition

(_parent.form.email.length<6)

and it works perfectly.

--> we're checking the variable, not the instance name for it's length

Now if I use the same logic on the other two variables

--> _parent.form.name_input.length<1
--> _parent.form.message_input.length<1

it does not work, so how do you or anybody else explain that ?

Mike
 
I'm sorry guys, maybe I'm just not getting it...

But Kenneth showed an excerpt from the help files which explains that they don't recommend using variables...

But my questions remain, how can it work for that one variable and not for the other 2 in the same if statement ?

All 3 variables are input text fields...

In my logic, it should either work for all 3 of the variables, or for none of them...
 
If you do not type anything into the TextField which Var is set to "name_input", the variable [tt]name_input[/tt] is [tt]undefined[/tt].

[tt]undefined[/tt] does not have any [tt]length[/tt] property, therefore the test [tt]if ((_parent.form.name_input.length<1) or (_parent.form.message_input.length<1))[/tt] is always false. It's false not because the length is more than 1, but because length does not exist.

Kenneth Kawamoto
 
Kenneth,

I don't think that's the case, because (as stated multiple times) I'm checking the other TextField with variable 'email' for it's length as well, with this condition:

_parent.form.email.length<6

Now, if I don't type anything into that text field with var 'email' to it, the condition works - it will not send out any data because it's waiting for the variable being greater than 6...

--> following your logic the var would be undefined, therefore it would proceed as in the two other TextField cases where it does not work...

That's why (as stated earlier multiple times) it does not make any sense to me why it works in that one case but not in the other two cases with the exact same setup...

Regards,

Mike
 
Put this trace [tt]trace("_parent.form.email: " + _parent.form.email);[/tt] before [tt]if(_parent.form.email.length<6)[/tt]. You should get "undefined" but from what you're saying you'll probably get empty string. If so the email TextField's Var is not the only place variable "email" is defined - do you have variable "email" defined as String elsewhere in your code? Another possibility is your email TextField already has " " (empty character) in it.

Kenneth Kawamoto
 
You state that you check the email for more than just length - so I assume the reason your email conditions trigger and yours others don't is your others check if they're < 1 and get false because its undefined but your email triggers because one of the other conditions is checkable and gets true, eg, does it contain an @. This your email triggers the error when left blank and the other 2 don't. Just a guess ;)

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top