The first two functions we write are "housekeeping" functions and will be called by other functions. The first, as you see here, simply checks to see if any data has been entered into the name field. This is a pretty simplistic check, but considering the different lengths of names, it's difficult to check for something more meaningful. If the field is empty, we set a new message for the message box and return false to the calling function, otherwise returning true.
The second function is similar in that it checks to see if any data has been entered into the email field. If it has, we then check to be sure it contains a "@" and a "." indicating that it's probably a valid email (it certainly isn't without these symbols!). Again, this is a bit simple, but with the varying lengths of names and the changing Upper Level Domains it's almost impossible to check for 100% accuracy.
The calling function will set visibility on the message box to make it appear and disappear, these functions simply do the checking as set the message box text to an appropriate message.
Next is another housekeeping function, also called by other functions. The clrData function is the "click handler" for the "Clear Form" button, and is also called after data is sent to the server to clear the variables and the screen.
This may look a little strange. In the past, I've always simply cleared the variable, and that also cleared the text from the screen. However, a little trial and error told me that clearing the variable contained in the LoadVars object (formData) didn't clear the text. In checking the debugger, it cleared the variable within the object only. So I have one line of code to clear the variable, and one line to clear the text from the screen.
|» Level Intermediate|
Rating: 9 Votes: 81
|Tom Watson is a Flash developer currently residing in Nashville, Tennessee. He's been an independant contractor in the computer business since 1989, working on web projects since the web was introduced to the Internet in 1994.|
|Download the files used in this tutorial.|
|Download (569 kb)|
|More help? Search our boards for quick answers!|