Quantcast
Channel: UltraMega Tech. » JavaScript
Viewing all articles
Browse latest Browse all 10

Default Form Values with jQuery

$
0
0
Here's a useful jQuery snippet that clears the default values of form fields on focus and refills them if no text is entered. It uses the attribute called defaultValue which stores the original value of a form field. $(document).ready(function() { $('input[type=text]').focus(function() { if($(this).val() == $(this).attr('defaultValue')) { $(this).val(''); } }) .blur(function() { if($(this).val().length == 0) { [...]

Viewing all articles
Browse latest Browse all 10

Trending Articles