In the world of web aesthetics a nice principle to follow is the less clutter the better. Traditional forms have contained a label and then a text input usually. More and more we’re beginning to see the labels being placed inside the text field until the user selects them, at which point they can type whatever. The reason we may be seeing it more often is because jQuery, as usual makes what is otherwise a fairly time-consuming task and makes it simple. To get an idea of what I’m talking about you can see a demo here. I checked the demo. I’m pretty sure that the tooltips work fine in Firefox, but are incorrectly positioned in Safari, and I don’t even want to know for IE. I’m sure this is no fault of the plugin, but that there is just some conflict in the plugin CSS and my demo template CSS. I just really didn’t feel like figuring it out. On top of all that, if you don’t have Firefox to view the demo with shame on you
Let’s think about what it is we are wanting to accomplish. Generally we want a form with no labels. Instead our labels are a prefilled value inside the form field. However, when a field with one of these prefilled labels is clicked or tabbed to we want to empty the field and ready it for typing. Next if new data is entered the data should stay in the field, and if no data is entered the field should return to the prefilled label. Lastly, if the user focuses a field that they have already entered data into we want to make sure that we don’t empty the field, but instead just select the entered data and ready it for editing. One last thing. Because our field label disappears when the field is selected I felt that it made sense to make sure that the user doesn’t forget what they are typing into the field. To accomplish this I used the jQuery Tools tooltip plugin. I won’t explain this too much, but for this demo I pretty much just copied and pasted their demo code from their site. Nonetheless, this is a really powerful and flexible plugin, and on top of everything really looks great.
On to the code. First we’ll take a look at the HTML.
The HTML
<!-- div that will show our tooltip -->
<div id="mytooltip"> </div>
<!-- form with labels in the field label in the 'id' and tooltip in the 'title' -->
<form name="myForm" id="myFormId" method="post" action="#">
<input type="text" name="firstname" id="Your First Name" value="" title="Enter Your First Name" /><br /><br />
<input type="text" name="lastname" id="Your Last Name" value="" title="Enter Your Last Name" /><br /><br />
<input type="text" name="mycolor" id="Your Favorite Color" value="" title="Enter Your Favorite Color" /><br /><br />
<input type="text" name="mycat" id="Your Favorite Cat" value="" title="Enter Your Favorite Cat" /><br /><br />
<input type="submit" name="mySubmit" />
</form>
(more…)