$(document).ready(function(){
 
  //call the function for each field with a label
  $("#myform label").each(function(){
    label = $(this).html();
    selector = "#"+$(this).attr("for");
    createValueLabel(selector, label);
  });
 
});
 
function createValueLabel (selector, defaultValue){
  //assign the default value to the form selector
  $(selector).data("default", defaultValue);
 
  //assign a function to the focus and blur events
  $(selector).bind("focus blur", function(){
    value = $(this).val();
 
    //if the current and default value are the same, clear the input field
    if(value==defaultValue){ $(this)
     .val("")
     .removeClass("value-label");
    }
 
    //if the field is empty, set the value to default
    if(!value){ $(this)
      .addClass("value-label")
      .val(defaultValue);
    }
  });
 
  //invoke the events to initialize the default value
  $(selector).trigger("focus").trigger("blur");
}
