The Best Web 2.0 Sign-up Form: Episode One
Monday, August 14th, 2006
Well it’s Monday, so let’s do something different. Let’s build a simple form with 2 fields: email address, and password. We want to focus on client side validation, so we will add a second password field to compare against and a password strength field. Password strength is becoming more and more popular, so we’ll build one with a twist - let’s animate it.
Now I have labeled this post as episode one. It will a complete post, however, we will add on to it in the weeks to come to create a full sign-up form with lots of cow bell! One last thing before I start cutting code. This article should be straight forward, maybe 2/5 in difficulty, using JavaScript/Prototype, CSS2 and XHTML.
Okay here we go, first things first. If someone makes an error or mistake, we want to display a custom message. Now, rather then having a message at the top of the screen saying what field the error is on, we are going to have a box dynamically inserted. Well, moved in the DOM pointing right at the field with a custom error message.
So the markup will look like this:

We will call this warning box, warningfs for frame set and hide it right off the bat. At this point it really dosent matter were in the body you put it because we will move it where we need it later. There are a few more components to this warning frame set:
tic: an image pointing up.
msg: id where the message will appear, and disappear when you click on it and
shadow: another box offset to give a shadow effect.
Â? Â? Click here to view the CSS file.
I’m not going to get into the nuts and bolts behind the actual markup as it should be easy to follow. I do want to point out that I used a table rather then div’s -Â? some habits take a long time to break.Â? I felt it would be quicker to write andÂ? less weight on my CSS, but really thats just an exscuse.
What we are going to do is loop through all the input fields and add a focus and blur event to each one, we are also going to validate off the focus and blur in the background.
var aElements = Form.getElements(’form1′);
for(var i=0;i Â? Event.observe(aElements[i],’blur’,fncBlurInput.bind(aElements[i]),false);
Â? Event.observe(aElements[i],’focus’,fncFocusInput.bind(aElements[i]),false);
}
To make the fields light up we use color fx - Tom Jensen (http://neuemusic.com/). I started writing my own color changer, but itÂ? was twice as many lines. Tom Jensen’s is very eleigant. While I’m on the subject of external libaries, we will also use Moo fx, http://moofx.mad4milk.net/, We need it to animate our password strength field and color fx extends it. If you get a chance, check out some of the other stuff Valerio Proietti is up to. It’s all very nice!
So lets have a look at those two functions:
Â? Â? function fncFocusInput() {
Â? Â? Â? Â? Â? Â? Â? var id = this.id;
Â? Â? Â? Â? Â? Â? Â? var colorSwap =Â? new fx.Color(this.id, {fromColor: “#FFFFFF”, toColor: “#EFEFEF”});
Â? Â? Â? Â? Â? Â? Â? var borderSwap = new fx.Color(this.id, {fromColor: “#CCCCCC”, toColor: “#0066FF”, property: “borderColor”});
Â? Â? Â? Â? Â? Â? Â? colorSwap.toggle();
Â? Â? Â? Â? Â? Â? Â? borderSwap.toggle();
Â? Â? Â? Â? Â? Â? Â? $(id).parentNode.insertBefore($(’warningfs’),$(id).nextSibling);
Â? Â? }
Â? Â? function fncBlurInput() {
Â? Â? Â? Â? Â? Â? Â? var id = this.id;
Â? Â? Â? Â? Â? Â? Â? var colorSwap =Â? new fx.Color(this.id, {fromColor: “#EFEFEF”, toColor: “#FFFFFF”});
Â? Â? Â? Â? Â? Â? Â? var borderSwap = new fx.Color(this.id, {fromColor: “#0066FF”, toColor: “#CCCCCC”, property: “borderColor”});
Â? Â? Â? Â? Â? Â? Â? colorSwap.toggle();
Â? Â? Â? Â? Â? Â? Â? borderSwap.toggle();
Â? Â? Â? Â? Â? Â? Â? if (id == ‘email’ && $(id).value.length > 3) {
Â? Â? Â? Â? Â? Â? Â? Â? Â? Â? Â? fncValidateEmail($(id));
Â? Â? Â? Â? Â? Â? Â? }
Â? Â? Â? Â? Â? Â? Â? if (id == ‘password2′) {
Â? Â? Â? Â? Â? Â? Â? Â? Â? Â? Â? fncPasswordMatch($(id));
Â? Â? Â? Â? Â? Â? Â? }
Â? Â? }
So, walking through the focus function, we set the new focus field and move our warning frame set to the field where there might be a warning. We still keep it hidden. On the blur function we set the color back to the origional, and check to see which field we are working on. If it’s the email field, we run a validate function, and if it’s the second password field, we check to see if it matches the first field.
Here is the email validation function:
Â? Â? function fncValidateEmail(objEmail) {
Â? Â? Â? Â? Â? Â? var strEmail = objEmail.value;
Â? Â? Â? Â? Â? Â? var pattern = /^[a-z][_.a-z0-9-]+@[a-z0-9][a-z0-9-]+\.[a-z]+([.]?[a-z][a-z]+)*/;
Â? Â? Â? Â? Â? Â? var results = pattern.test(strEmail);
Â? Â? Â? Â? Â? Â? Â?
Â? Â? Â? Â? Â? Â? if (results == false) {
Â? Â? Â? Â? Â? Â? Â? Â? Â? Â? $(’warningfs’).style.top = getActualTop(objEmail) + 33;
Â? Â? Â? Â? Â? Â? Â? Â? Â? Â? $(’warningfs’).style.left = getActualLeft(objEmail);
Â? Â? Â? Â? Â? Â? Â? Â? Â? Â? $(’warningmsg’).innerHTML = “Please enter a valid email address.”;
Â? Â? Â? Â? Â? Â? Â? Â? Â? Â? $(’warningfs’).style.display = “block”;
Â? Â? Â? Â? Â? Â? } else {
Â? Â? Â? Â? Â? Â? Â? Â? Â? Â? $(’warningfs’).style.display = “none”;
Â? Â? Â? Â? Â? Â? }
Â? Â? Â? Â? Â? Â? return;
Â? Â? }
This is a simple regular expression. If there is an error, we display our warning frame set, else, we make sure it’s hidden. The PasswordMatch function is also quite similar. Check the source for that function.
Now the other big test we do is check the password strength. I’ve kept it out of the focus, blur loop and added the listener to the bottom of the init function ‘onkeyup’. Our password strength is going to be based on a series of tests: is it more then 5 characters, does it have at least one number, does it have at least one uppper case letter, and does it have one special character. Feel free to play with this and make it better.
To create the actual effect, we have two DIV’s sitting on top of each other using z-index, and we use fx.width to animate the top div to show the password getting stronger or weaker. It’s a nice effect and really not too difficult to recreate.
We are done, for now. I really hope you have enjoyed this tutorial, and if you have any questions, please let me know. Also, check back shortly to see how to add IP/GEO lookup checking and Postal/Zip to City checking.
Download and Demo:
Â? Â? Â? Click here to view the demo.
Â? Â? Â? Click here to download the compete souce zip.
References:
Â? fx color - Tom Jensen (http://neuemusic.com/)
Â? moo fx - Valerio Proietti (http://moofx.mad4milk.net/)






It would be foolish to assume or even suggest that the recent deal, the recent $900 million deal to be exact, between search giant 
Proving yet again that he’s at the top of the game on the Internet,
It’s difficult to look at the website and really pin down any one thing that caused it to, almost out of nowhere, grow into arguably the most dominant force on the Internet. Look at
Starting in July 2003, it took MySpaceÂ? less than ten months to make it to the top of the category, and the growth didn’t stop there (as shown in the table to the left).Â? But, all these sites are the same, aren’t they? There are obviously several factors that lead toÂ? the website achieving what it did.

