The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › CSS › A question on form styling
How do you get text into a input? I’m looking to find a way to have text in a input by default, such as chris has "search" in his input. If anyone knows how please let me know.
what I do is use a little jQuery:
<input type="text" name="search" value="Search…" id="search" />
then like…
//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 :)