debugging - What is wrong with this jQuery .blur? -


i have jquery:

var testtitleval = $('#testtitle').val(); $('#testtitle').blur(         function(){            if(testtitleval.length == 0){                  $('#testtitle').val('title');            }        }); 

to work on html:

<input type="text" id="testtitle"> 

what want accomplish when focus leaves input , there no text in input makes value title. reason not doing that. ideas?

you code bit off in if statement:

do instead:

$('#testtitle').blur(     function(){        if($(this).val().length == 0){              $(this).val('title');        }    }); 

fiddle: http://jsfiddle.net/maniator/c6aau/


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -