UltraMega Blog
22Oct/090

The ‘War’ on IE6

Recently I've been noticing a trend among Web developers to "take action" against MS Internet Explorer 6. From putting badges on their Twitter avatars to designing websites to detect and block IE6, many designers and developers are coming up with their own ideas to help end the browser's reign of terror. My question is, are some of these methods appropriate or even in their best interests?

15Oct/093

Default Form Values with jQuery

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) {
         $(this).val($(this).attr('defaultValue'));
      }
   });
});

For example, assume you have a field like this:

<input type="text" value="Search..." />

When the page loads, the text field will have "Search..." filled in. When you focus on it, this text will disappear (assuming it hasn't already been edited by you). When you leave focus without typing anything, the text will reappear.