Return to Snippet

Revision: 48017
at June 22, 2011 01:33 by cdurocher


Initial Code
<script type="text/javascript">
	$(document).ready(function() {
		swapValue = [];
		 $("#qvtit-qvtit").each(function(i){
		 swapValue[i] = $(this).val();
		 $(this).focus(function(){
		   if ($(this).val() == swapValue[i]) {
			 $(this).val("");
		    }
		   $(this).addClass("focus");
		 }).blur(function(){
		   if ($.trim($(this).val()) == "") {
		       $(this).val(swapValue[i]);
		       $(this).removeClass("focus");
	            }
		 });
	     });
	});
</script>

Initial URL

                                

Initial Description
Specifiy a default value to input text field. OnFocus, the default value clear and let you type a new value. If typed value is erased then the default value is set back.

Initial Title
jQuery: Input text default value, clear value on click, if typed value erased, get default value back

Initial Tags
form, jquery

Initial Language
jQuery