A small jQuery plugin I wrote which I thought I would make public. Instead of using
<label> elements for each of your form’s fields, use the input’s value attribute to set the label. Clear-on-focus will then take care of clearing the value when a user clicks or focuses the field. If they leave the field blank, the original message is reset back. Also works correctly for password fields. Example usage:
<input type="text" name="username" value="Enter username" class="clear-on-focus" />
<input type="text" name="password" value="Enter password" class="clear-on-focus password" />
Link: github repository
This is one of those routine web development things which you assume is inbuilt, but actually proves quite tedious to find a nice solution to.
Specifically, I am talking about converting something like ' to ‘ or & to & directly in Javscript.
This function does exactly that! Note how it adds a function to the prototype for String, so is called in the following way:
I’ve referred to this so many times I thought it would be good to post it here: