Notes reSet value on an input field with jQuery
- Published
- November 9, 2010
- Written by
- Andreas Nymark
- Labeled with
- jquery, javascript, plugin
reSetValue is small plugin made with jQuery. It is used for resetting one or more input field values when user puts focus on it and set the previous default value back if the user doesn't change the value.
This little plugin can be used in a search field, where you usually use a term like "Search here" in the input field and you need to reset the value when user puts focus on that field. If the user doesn't change the value it will put back the initial value when input field is out of focus. If the value is changed, the script will not erase the value every time the user puts the field in or out of foucs.
How to use it
Just include the jQuery framework and the reSetValue-plugin and you're ready for lift off:
$(document).ready(function() { $('input').reSetValue(); });
If you want to use it on more than one field, just type all the selectors comma separated—like this:
$('input, textarea, .search, #name').reSetValue();
Download jquery.reSetValue.js