Flash Form Validation

Is there any way to validate several custom checkboxes to make sure that at least one is checked?

How can I validate a phone number to make it numeric.

I need the validation to work with code similar to:

on (press) {
if (!firstname.length) {
loadMovie(“error-movie.swf”, 1);
} else if (!lastname.length) {
loadMovie(“error-movie2.swf”, 1);
else {
loadVariables(“url”, “_parent”, “POST”);
}
}

Please Help!!

tia!!

with javascript or with [URL=http://www.flashcircle.com/display.php?storyid=62]flash itself?

The first tutorial is actually a pretty good one, showing you how with javascript. The second is very basic, but you’ll get the idea and will probably be able to create you’re own after you’re done with it.

I don’t get what you mean by adding that code to the validation… you mean if it does find an error, you want that script to work?

Must be Flash.

I provided the code that worked for other variables. I cannot seem to get any variation of that to work for the checkboxes (require one checked) and phone number (to make it require numeric values).

Javascript cannot be used because it must be a self contained movie on a third party website.

I hope that makes it clearer.

Thanks!!

Phone number part is easy, just click character, and then choose only numerals (0-9). That won’t let the user put anything but numerals inside the input box.

About the checkboxes, that requires a bit of coding.


if( checkbox1.getEnabled() ) {} else { if(checkbox2.getEnabled() } else { if(checkbox2.getEnabled() ) {} else {loadMovie(error.swf);} } }

the getEnabled method of a checkbox returns a true or false value on whether the box is checked or not. If you keep testing until the last one, you can put the error movie inside the deepest if else statement, then just close all of them. The code above is way screwed up, I’m writing this in a rush, but I think you get the idea ;).

Thanks, but it didnt work.

I am using older smart-clips for the checkbox because the MX version does not send correct variables to certtain databases.

Theses boxes send back true or false variables.

well, i don’t know much about that, so i’ll leave it to an expert to answer that :slight_smile:

This is what worked for anyone who comes across this problem:

If you just want to check if any checkboxes are checked that should not be too hard. You want to set a variable when the checkbox is checked. Then test to see if that variable is set or not.
I don’t know how you made your custom checkboxes but there has to be some part of code that puts the check in and takes it off when the user clicks. Add this to the check on part,
_root.myVar++
And this to the check off part,
_root.myVar–

Then test it (I guess on a button push),
on (press) {
if (_root.myVar>0) {
loadMovie(“a_box_is_checked.swf”, 1);
} else {
loadMovie(“no_box_is_checked.swf”, 1);
}
}