Home › Forums › CSS › A question on form styling › Re: A question on form styling
May 16, 2010 at 1:40 pm
#75817
Rob MacKay
Participant
what I do is use a little jQuery:
<input type="text" name="search" value="Search…" id="search" />
then like…
Code:
$(function() {
//target search box when use focuses
$(“#search”).focusin(function() {
//target search box when use focuses
$(“#search”).focusin(function() {
//Removes the value.
$(this).removeAttr(“value”);
});
//listens for the focus out…
$(“#search”).focusout(function() {
//check if a user has added a value
if($(this).val()) {
// if they have – do nothing because you want to keep theirs
} else {
// If they have not, and the field is blank – add the value again…
$(this).val(“Search…”);
}
});
});
That, although it’s the long way round code wise, should provide a solution that you can learn from :)