I’ve got a little validation plugin that I’ve written, and I’m setting data("defaultvalue") to the value on document ready, but it seems there’s a wee bug when it comes to auto form completers, they beat me to it.
if($(this).val() != ""){
$(this).data("defaultvalue", $(this).val());
}
This is the code I’m using to store the default value, or “placeholder text”, and later checking it with:
if($(this).data("defaultvalue") && $(this).val() == $(this).data("defaultvalue")) $(this).val("");
Any ideas to skip around auto-completion? Or should I just bite the bullet and set the default value data attribute in the markup?
And yes, the only reason I’m not using the placeholder attribute, is because of IE. Thank you Microsoft.
For those that come across this same problem, I ended up going with setting the data attribute in my markup.
<input value="Days" data-defaultvalue="Days" />It feels a bit like double-handling, but it’s the best cross-browser solution to avoid auto-completion scripts.