Using Form Labels as Input Values with jQuery
I recently modified the comment forms on this site. Rather than having a separate label and input field, I used jQuery to put the contents of the label tags inside the inputs themselves.
Why waste space with labels? I think it gives a nice clean look. I’m thinking about refining this idea and bundling it into a jQuery plugin.
Update 3/6/2009: I revisited it to make it more generic. Also, it’s minified so it’s harder to review. But feel free to download it and test it. All you have to do to use it is to add it to is add the script and jQuery to your page and call “initMagicLabels();” it takes a jQuery selector to identify which form(s) you want it to apply to.
If you want it to apply to every form on the page, just pass it “form” as an argument. You can also do the id of the form for example:
or a class: