Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HTML onfocus event

    I am trying to have the words Search appear in a searchbox when the page is first open and then disappear when someone clicks in the search box. This is the part of the code I think I need to insert the code to do this I am just not sure where I would insert it.

    [<div id="portal-searchbox"
    i18n:domain="plone">
    <form name="searchform"
    action="search"
    tal:attributes="action string:${view/navigation_root_url}/search">

    <div class="LSBox">
    <label for="searchGadget" id="search-label"
    i18n:translate="text_search">Search</label>

    <input name="SearchableText"
    type="text"
    size="18"
    value=""
    accesskey="4"
    i18n:attributes="title title_search_site;"
    tal:attributes="value request/SearchableText|nothing;
    id view/search_input_id"
    class="" />

    <input class="searchButton"
    type="image"
    value="Search"
    src="search-button.png"
    tal:attributes="src string:${context/portal_url}/search-button.png;"
    i18n:attributes="value label_search;" />
    <div id="search-second-line"> ]

  • #2
    Registered User
    Join Date
    Jun 2011
    Posts
    1,063
    Thanks
    12
    Thanked 241 Times in 240 Posts
    You can't do that legitimately in HTML/CSS, other than using a <label>.

    Here's a good jQuery snippet for what you are looking for: http://nick.boldison.com/websites/jq...ocus-function/
    And at the bottom of this snippet, there is an example: http://www.eggchops.com/blogexamples...learFocus.html

    In order to use jQuery, just add this line to your <head> tag:

    Code:
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
    Hurry though! VIP is going to get here and say loading jQuery is unnecessary!
    To which I will respond, most websites use jQuery by Google, so chances are it will be cached!

    Edit: OH NO HE'S HERE! You're on your own kid!
    Last edited by Sammy12; 09-19-2012 at 09:13 PM.

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,726
    Thanks
    6
    Thanked 1,013 Times in 986 Posts
    Ha, you got me! I was almost gonna chime in. OK, I give you the caching thing. Although, besides that, I’m not a fan of randomly recommending someone to use jQuery who probably doesn’t even have a slight idea of plain JavaScript in the first place. I see too many questions related to jQuery caused by lack of understanding due to people randomly copying and pasting stuff because it makes shiny effects and “everybody is using it”. But go ahead; what do I care?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •