-
form field to check length of input text
i'm trying to get a Flash form to test certain conditions, one of which is the full date (ie 2006 as opposed to 06), but the AS below (in bold) isn't working... does anybody know the right script?
on (release) {
if (!name.length) {
text.emailstatus = "please enter your name";
} else if (!email.length || email.indexOf("@") == -1 || email.indexOf(".") == -1) {
text.emailstatus = "please enter a valid email";
} else if (!message.length) {
text.emailstatus = "please enter your message";
} else if (!year.length < 4) {
text.emailstatus = "please enter the full year";
} else {
loadVariablesNum("MailPHP.php", "0", "POST");
text.emailstatus = "message sent - thankyou";
}
}
-
i think you're trying to say "if year is less than 4 chars long give error"
which you could do like you are, but you need to change the order its evaulated, usually accomplished by parenthesising - just like in normal math
so instead of !year<4 use !(year<4)
but you want it to be exactly 4 long, so the best bet would be to say year!=4
-
Total Universe Mod
try
Code:
}else if (year.length != 4){
-
thanks very much! works perfectly
-
i'm using the same script and advice (Actionscript 2), as below, but now this isn't working.....
Code:
if (name.length != 5) {
nametitle.text = "enter your full name";
I don't want the number of characters in the name to be less than 5.
can somebody please tell me why it keeps telling me to "enter your full name" when i have far more than 5 characters entered?
thanks
-
is there anyone who can please help me with this?
-
You just need it to say:
Code:
if (name.length < 5)
What you have now will tell you to enter your full name unless the name is exactly 5 letters long
-
thanks for the reply cessnajumpin, but it doesn't work. wondering if there is some conflict somewhere. here is the full code for the button...
on (release) {
if (name.length<5) {
nametitle.text = "please enter your full name";
} else if (!email.length || email.indexOf("@") == -1 || email.indexOf(".") == -1) {
emailtitle.text = "please enter a valid email";
} else {
loadVariablesNum("NewsletterPHP.php", "0", "POST");
mcNavNewsletter.gotoAndPlay('fade');
btnews.enabled = false;
mcResponse.gotoAndPlay(2);
}
}
on (rollOver) {
mcNavNewsletter.gotoAndPlay('over');
}
on (rollOut) {
if (mcNavNewsletter._currentframe>1) {
mcNavNewsletter.gotoAndPlay('out');
}
}
(the email code works fine)
-
What part isn't working? Just the name? Is it still giving you the "please enter..." or something else?
-
ideally i'd like someone to enter their name so that the default "name" isn't accepted (thus the reason for more than 5 letters), and also that people enter longer full names etc.
at the moment it's only the email address part that works ok.
please take a look... http://www.fkda.co.uk then select "practice" then "news"
(don't worry about sending test name/email... will just delete afterwards)
-
That's weird..it could be something with using the variable "name".
What happens when you use this for the validation:
Code:
if (nametitle.length < 5) {
-
good idea... changed the variable to "fullname" but still not working. code now is.......
Code:
on (release) {
if (fullname.length<5) {
nametitle.text = "please enter your full name";
} else if (!email.length || email.indexOf("@") == -1 || email.indexOf(".") == -1) {
emailtitle.text = "please enter a valid email";
} else {
loadVariablesNum("NewsletterPHP.php", "0", "POST");
mcNavNewsletter.gotoAndPlay('fade');
btnews.enabled = false;
mcResponse.gotoAndPlay(2);
}
}
on (rollOver) {
mcNavNewsletter.gotoAndPlay('over');
}
on (rollOut) {
if (mcNavNewsletter._currentframe>1) {
mcNavNewsletter.gotoAndPlay('out');
}
}
-
Ok, try using the text field itself as the validation. What happens when you try:
Code:
if (nametitle.length < 5) {
-
that doesn't work either :-(
-
-
will try to strip the fairly large file down to just this section (news page) over the weekend.
incidentally i added an exclamation in front of the variable (as below), and it then prompted for "full name", but this then wouldn't disappear no matter how many characters i entered.
PHP Code:
if (!fullname<5) {
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|