This is just drivin me nuts!
I tried If/If else … not working… I tried switch… not working!
Is it Flash or is it just me?
sendername is a textfield… and mail1 is also a textfield
on (release) {
namefield = sendername.toLowerCase();
mailfield = mail1.toLowerCase();
switch (sendername) {
case "" :
mailstatus = "Invalid name!";
break;
default :
switch (namefield.indexOf("syko")) {
case '0' :
mailstatus = "Invalid name!";
break;
default :
switch (mail1) {
case '' :
mailstatus = "E-mail #1 is invalid!";
break;
default :
switch (mail1.indexOf("@")) {
case '0':
mailstatus = "E-mail #1 is invalid!";
break;
default :
switch (mail1.indexOf(".")) {
case '0' :
mailstatus = "E-mail #1 is invalid!";
default :
mailstatus = "OK"
}
}
}
}
}
}
Just not working!
When I just press submit without filling anything it says "OK"then I type something into the name field… it says “OK”, I delete the text typed and press submit… it says “Invalid name”… I don’t get it!:x
Syko: The organization of your code is confusing, the form validation process can be achieved using a for-in loop to check your input textfields, an if statment that checks weather the property is an instanceof TextField, and another if statement that checks if the property is an empty string. simple way to do it would look like:
for (var prop in form) {
if (form[prop] instanceof TextField) {
if (form[prop].text == "" /*|| other conditions goes here*/ ) {
trace("complete the whole form");
break;
}
}
}
I’ve never use for-in before! (nor instanceof) That one seems completely new to but I think I understod it pretty well… though it’s not working!
I nedd to make an object before that right? like
form = { name:sendername, mail:mail1 };
This is pretty confusing!
And senocular I can’t say I understand what you mean by -1 won’t equal to -1!
form is the movieclip which contains the textfields.
And what senocular meant is to change ‘-1’ into (-1). (Strict Equality is what the switch statement use, Unlike the If statement, which uses automatic datatype conversion)
trace(1 === “1”)//returns false, It’s Strict, no automatic datatype conversion with this operator
trace(1 == “1”)//returns true, unlike the strict equality, there is automatic datatype conversion with this operator