Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS A question on form styling

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #29046
    thestauss
    Member

    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.

    #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() {

    //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 :)

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘CSS’ is closed to new topics and replies.