CSS:
.promptwrapper{
position:relative;
}
.overlayprompt{
position:absolute;
color:#cccccc;
top:2px;
left:4px;
}
JS:
function doOverlayPrompt(input,overlay){
input.focus(function(){overlay.hide();})
.blur(function(){
alert(input.val());
if(input.val() == "") overlay.show();
else overlay.hide();
}).blur();
overlay.click(function(){
input.focus();
});
}
example HTML:
<span class="promptwrapper"><div class="overlayprompt editFIELD_prompt">FIELD</div><input class="editFIELD"></span>
example JS:
doOverlayPrompt($(".editFIELD"),$(".editFIELD"));
So looking back right now I see this is a bad idea for 3 or so reasons:
- it's better for forms you expect to be blank, vs. stuff a user would come back and edit later, because they might not be able to tell what field is what.
- damn it, I've written this before!
- And worst of all html5 has a nice "placeholder" tribute for input tags now, which does almost exactly this. As long as you don't need to support IE earlier than version 10....
No comments:
Post a Comment