Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 19 of 19

Thread: Default Search Text

  1. #1
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default Default Search Text

    Hello,

    I was wondering how I would go about adding default search text to the search box... Something like, "search our catalog..." And when they click in the search box, that text disappears and they can start typing.

    Cheers,

    ~D

  2. #2
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

  3. #3
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    Quote Originally Posted by BFG 9000 View Post
    For some reason, this is not working... :-/

  4. #4
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    Does anyone else have any ideas please?

  5. #5
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Well the example I gave clearly does work - there's a demo right on the page.
    Can you be more specific about why it's not working for you?

    Can you give me a url to where you've implemented it?
    (I normally create a new topic for testing this kind of thing).
    Here's a topic I created to test it : http://www.3mselect.co.uk/t-donato.aspx (use password donato)
    I copied & pasted the code exactly as they give it on the page I linked to earlier.


    Here's the exact contents of the topic :-

    C#/VB.NET Code:
    <style media="screen" type="text/css">
        .
    defaultText width300px; }
        .
    defaultTextActive color#a1a1a1; font-style: italic; }
    </style>
    <
    script language="javascript">
    <!--
    $(
    document).ready(function()
    {
        $(
    ".defaultText").focus(function(srcc)
        {
            if ($(
    this).val() == $(this)[0].title)
            {
                $(
    this).removeClass("defaultTextActive");
                $(
    this).val("");
            }
        });
        
        $(
    ".defaultText").blur(function()
        {
            if ($(
    this).val() == "")
            {
                $(
    this).addClass("defaultTextActive");
                $(
    this).val($(this)[0].title);
            }
        });
        
        $(
    ".defaultText").blur();        
    });
    //-->
    </script>
    <input class="defaultText" title="e.g. someone@example.com" type="text"> 

    Note that I didn't add the following code as I already call jquery in the template :-

    C#/VB.NET Code:
    <script src="//code.jquery.com/jquery-1.8.3.min.js" type="text/javascript">/script

    TTFN

    BFG

  6. #6
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    I want to use this for the default search box though in the aspdotnetstorefront...

  7. #7
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    I would like to send you the URL... Do have an email I can send it to?

  8. #8
    donttryathome is offline Senior Member
    Join Date
    Apr 2009
    Posts
    171

    Default

    Donato,

    Did you make sure to download and install JQuery? You won't be able to just add the code to your template, you'll also have to download the jquery file and put it in your jscripts folder (or wherever else you want) and reference that file in the script src tag.

    (Or you could do as BFG does and pull the jquery file from a remote site)
    Running: AspDotNetStorefront ML 8.0.1.2/8.0.1.2

  9. #9
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    Quote Originally Posted by donttryathome View Post
    Donato,

    Did you make sure to download and install JQuery? You won't be able to just add the code to your template, you'll also have to download the jquery file and put it in your jscripts folder (or wherever else you want) and reference that file in the script src tag.

    (Or you could do as BFG does and pull the jquery file from a remote site)
    Yes. I have it in there:

    <script type="text/javascript" src="../../jscripts/jquery-1.8.2.min.js"></script>

  10. #10
    donttryathome is offline Senior Member
    Join Date
    Apr 2009
    Posts
    171

    Default

    Try referencing the jquery library without the full relative path:

    Code:
    <script type="text/javascript" src="jscripts/jquery-1.8.2.min.js"></script>
    Running: AspDotNetStorefront ML 8.0.1.2/8.0.1.2

  11. #11
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Just had a look at the site link you emailed me.

    I can't see any of the code above (except a call to jquery) in the source of the page.

    The javascript relies on it (the search box) having a class of defaultText and a title of whatever you want the default text to be.


    TTFN

    BFG

  12. #12
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    Quote Originally Posted by BFG 9000 View Post
    Just had a look at the site link you emailed me.

    I can't see any of the code above (except a call to jquery) in the source of the page.

    The javascript relies on it (the search box) having a class of defaultText and a title of whatever you want the default text to be.


    TTFN

    BFG
    I have this in there right before the </head> tag:

    Code:
    <script language="javascript">
    <!--
        $(document).ready(function() {
            $(".search").focus(function(srcc) {
                if ($(this).val() == $(this)[0].title) {
                    $(this).removeClass("searchTextActive");
                    $(this).val("");
                }
            });
    
            $(".search").blur(function() {
                if ($(this).val() == "") {
                    $(this).addClass("searchTextActive");
                    $(this).val($(this)[0].title);
                }
            });
    
            $(".search").blur();
        });
    //-->
    </script>
    I just changed the style names...

  13. #13
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    And now I have Google's JQuery library referenced:

    Code:
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

  14. #14
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Your search text <input> field doesn't have the class or the title attributes.

    C#/VB.NET Code:
    <input name="ctl00$ctrlSearch$SearchTexttype="text" id="ctl00_ctrlSearch_SearchText"
    Instead, they're on a <span> which is the parent of a <div> which is a parent of the <input>.



    TTFN

    BFG

  15. #15
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    Quote Originally Posted by BFG 9000 View Post
    Your search text <input> field doesn't have the class or the title attributes.

    C#/VB.NET Code:
    <input name="ctl00$ctrlSearch$SearchTexttype="text" id="ctl00_ctrlSearch_SearchText"
    Instead, they're on a <span> which is the parent of a <div> which is a parent of the <input>.



    TTFN

    BFG
    In the homepage.master, the search box is an aspdotnetstorefront control:

    Code:
                <div style="float: right">
                            <aspdnsf:Search ID="ctrlSearch" runat="server" CssClass="search" SearchButtonCaption="Go"
                    SearchCaption="<%$ Tokens: StringResource, common.cs.82 %>" SearchTextMinLength="<%$ Tokens:AppConfigUSInt, MinSearchStringLength %>"
                    SearchTextMinLengthInvalidErrorMessage="<%$ Tokens: StringResource, search.aspx.2 %>"
                    ValidateInputLength="true" ShowValidationMessageBox="true" ShowValidationSummary="false" Title="search our catalog..." />
                    <a runat="server" class="account" href="~/account.aspx"><%--My Account--%></a></div>

  16. #16
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Here's a really nice guide to creating a custom search control written by mbertulli.


    TTFN

    BFG

  17. #17
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    Quote Originally Posted by BFG 9000 View Post
    Here's a really nice guide to creating a custom search control written by mbertulli.


    TTFN

    BFG
    Thank you. But I cannot get this to work either...

  18. #18
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Erm... could you hard code it into homepage.master instead of using a control?

    Clutching at straws a little now...



    TTFN

    BFG

  19. #19
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    Quote Originally Posted by BFG 9000 View Post
    Erm... could you hard code it into homepage.master instead of using a control?

    Clutching at straws a little now...



    TTFN

    BFG
    I am not sure how to implement the search WITHOUT a control...