I have the following jQuery code:
$(".SearchForm input:text").each(function(){
if(allowedDefaults.indexOf($(this).val()) > 0 || $(this).val() == "")
{
$(this).attr("defaultvalue", $(this).val());
$(this).css("color","#9d9d9d");
$(this).focus(function(){
if($(this).val() == $(this).attr("defaultvalue"))
{
$(this).val("");
$(this).css("color","#4c4c4c");
}
});
$(this).blur(function(){
alert("ud");
if($(this).val() == "")
{
$(this).val($(this).attr("defaultvalue"));
$(this).css("color","#9d9d9d");
}else
{
$(this).removeClass("ignore");
}
});
}
});
I use this code to insert some default text into some of the input fields when nothing is typed. This means that when the user sees my search form, the default values will be set as an attribute at the input level, field, and this will be the displayed value. When the user clicks inside the input field, the default value will be deleted.
When the user sees the input field first, he looks like this:
<input type="text" value="" defaultvalue="From" />
, . - , , .
, -, . , , , ?
, , :
<input type="text" value="someValue" defaultvalue="From" />
.
, ? , , .
,