Making default entry in search text box disappear on click

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • spence

    Making default entry in search text box disappear on click

    Hi All

    How do I make it so that when a user clicks in a search text field, the
    default entry (in this case "Search") is removed automatically - they
    are then faced with a blank search box and can type straight away

    Thanks in advance

  • Philip Ronan

    #2
    Re: Making default entry in search text box disappear on click

    "spence" wrote:
    [color=blue]
    > Hi All
    >
    > How do I make it so that when a user clicks in a search text field, the
    > default entry (in this case "Search") is removed automatically - they
    > are then faced with a blank search box and can type straight away
    >
    > Thanks in advance
    >[/color]

    <INPUT type="text" value="Search" onfocus="if
    (this.value==th is.defaultValue ) this.value='';" >

    --
    phil [dot] ronan @ virgin [dot] net



    Comment

    • spence

      #3
      Re: Making default entry in search text box disappear on click

      Brilliant. Thanks philip.

      I tried searching other groups but couldn't find a thing! Perhaps it
      was my search criteria? Anyway, it's here now if anyone uses the same
      search criteria I was using!

      Thanks again

      Comment

      • Jukka K. Korpela

        #4
        Re: Making default entry in search text box disappear on click

        "spence" <benny.spencer@ gmail.com> wrote:
        [color=blue]
        > Brilliant.[/color]

        Really? You got a wrong answer. That's what you usually get by asking
        in a wrong group. Dynamic modification of a field's content is not an
        HTML matter.
        [color=blue]
        > I tried searching other groups but couldn't find a thing! Perhaps it
        > was my search criteria? Anyway, it's here now if anyone uses the same
        > search criteria I was using![/color]

        Well, maybe I then need to mention that the answer is wrong.

        It is wrong because it relies on security holes in browsers (it does
        not work if the browser has client-side scripting disabled), for doing
        something that need not be done at all. A search box should have
        initial content only if the initial content is a _meaningful and useful
        default_. It would then be absurd to wipe it out.

        --
        Yucca, http://www.cs.tut.fi/~jkorpela/
        Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

        Comment

        • Benjamin Niemann

          #5
          Re: Making default entry in search text box disappear on click

          Jukka K. Korpela wrote:
          [color=blue]
          > "spence" <benny.spencer@ gmail.com> wrote:
          >[color=green]
          >> Brilliant.[/color]
          >
          > Really? You got a wrong answer. That's what you usually get by asking
          > in a wrong group. Dynamic modification of a field's content is not an
          > HTML matter.
          >[color=green]
          >> I tried searching other groups but couldn't find a thing! Perhaps it
          >> was my search criteria? Anyway, it's here now if anyone uses the same
          >> search criteria I was using![/color]
          >
          > Well, maybe I then need to mention that the answer is wrong.
          >
          > It is wrong because it relies on security holes in browsers (it does
          > not work if the browser has client-side scripting disabled), for doing
          > something that need not be done at all. A search box should have
          > initial content only if the initial content is a _meaningful and useful
          > default_. It would then be absurd to wipe it out.[/color]

          If (and only if) there's really a good reason to do something like this, the
          'default' (which is probably not a default at all..) should be removed and
          *inserted* using scripting, so non-scripted clients just get a blank input.
          I've seen too many form submissions like 'Your NameFred Smith' or 'Your
          Emailfred@examp le.com' (that was my hard way to learn that this is a bad
          idea).


          --
          Benjamin Niemann
          Email: pink at odahoda dot de
          WWW: http://www.odahoda.de/

          Comment

          • Philip Ronan

            #6
            Re: Making default entry in search text box disappear on click

            "Jukka K. Korpela" wrote:
            [color=blue]
            > It is wrong because it relies on security holes in browsers (it does
            > not work if the browser has client-side scripting disabled), for doing
            > something that need not be done at all.[/color]

            Get real. This has nothing to do with security holes.

            If Javascript is disabled, then the user can delete it with a single
            keypress. So what's the problem? Spare us the dogma, please!!

            --
            phil [dot] ronan @ virgin [dot] net



            Comment

            • Jukka K. Korpela

              #7
              Re: Making default entry in search text box disappear on click

              Philip Ronan <invalid@invali d.invalid> wrote:
              [color=blue]
              > "Jukka K. Korpela" wrote:
              >[color=green]
              >> It is wrong because it relies on security holes in browsers (it
              >> does not work if the browser has client-side scripting disabled),
              >> for doing something that need not be done at all.[/color]
              >
              > Get real. This has nothing to do with security holes.[/color]

              You never heard of such holes? Not very real.
              [color=blue]
              > If Javascript is disabled, then the user can delete it with a
              > single keypress.[/color]

              Can he? Are you sure?
              [color=blue]
              > So what's the problem?[/color]

              There was no problem before someone created it by using a default entry
              that ain't no default entry but just an annoyance.
              [color=blue]
              > Spare us the dogma, please!![/color]

              Did you have something to say about HTML authoring for the WWW?

              --
              Yucca, http://www.cs.tut.fi/~jkorpela/
              Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

              Comment

              • Philip Ronan

                #8
                Re: Making default entry in search text box disappear on click

                "Jukka K. Korpela" wrote:
                [color=blue]
                > Philip Ronan <invalid@invali d.invalid> wrote:
                >[color=green]
                >> "Jukka K. Korpela" wrote:
                >>[color=darkred]
                >>> It is wrong because it relies on security holes in browsers (it
                >>> does not work if the browser has client-side scripting disabled),
                >>> for doing something that need not be done at all.[/color]
                >>
                >> Get real. This has nothing to do with security holes.[/color]
                >
                > You never heard of such holes? Not very real.[/color]

                OK please explain what's so insecure about using Javascript to clear the
                initial contents of a search box.
                [color=blue][color=green]
                >> If Javascript is disabled, then the user can delete it with a
                >> single keypress.[/color]
                >
                > Can he? Are you sure?[/color]

                OK, I have to admit I haven't tested this functionality in every single
                browser. I've got better things to do, as it happens. But from my experience
                most browsers select the contents of text boxes when they receive focus. If
                not, then the user just has to hold the key down a bit longer until the
                auto-repeat kicks in. Or if the user is really pressed for time, perhaps
                control+delete might do it, or (gasp) control-A, delete. This isn't really a
                big deal.
                [color=blue][color=green]
                >> So what's the problem?[/color]
                >
                > There was no problem before someone created it by using a default entry
                > that ain't no default entry but just an annoyance.[/color]

                An annoyance to you perhaps, but you seem to be the sort of person that gets
                annoyed very easily.
                [color=blue][color=green]
                >> Spare us the dogma, please!![/color]
                >
                > Did you have something to say about HTML authoring for the WWW?[/color]

                Sure. If you want to add a search box to your web pages but you don't have
                much space available, here's something you could try: Create a form with a
                single INPUT box containing "Search" as the initial text. That way you can
                indicate the purpose of the search box without cluttering your design with
                additional LABEL or LEGEND elements. You can even use Javascript to clear
                this initial text when the text box receives the focus. Just don't tell
                anyone at c.i.w.a.h what you've done.

                Will that do?

                --
                phil [dot] ronan @ virgin [dot] net


                Comment

                • Alan J. Flavell

                  #9
                  Re: Making default entry in search text box disappear on click

                  On Wed, 6 Jul 2005, Philip Ronan wrote:
                  [color=blue]
                  > "Jukka K. Korpela" wrote:
                  >[color=green]
                  > > You never heard of such holes? Not very real.[/color]
                  >
                  > OK please explain what's so insecure about using Javascript to clear the
                  > initial contents of a search box.[/color]

                  What's insecure is allowing an untrusted site to execute javascript on
                  one's browser. The intended purpose is irrelevant for this. If you
                  don't yet know this, then you aren't in a position to argue about it.

                  Comment

                  • Philip Ronan

                    #10
                    Re: Making default entry in search text box disappear on click

                    "Alan J. Flavell" wrote:
                    [color=blue]
                    > On Wed, 6 Jul 2005, Philip Ronan wrote:
                    >[color=green]
                    >> "Jukka K. Korpela" wrote:
                    >>[color=darkred]
                    >>> You never heard of such holes? Not very real.[/color]
                    >>
                    >> OK please explain what's so insecure about using Javascript to clear the
                    >> initial contents of a search box.[/color]
                    >
                    > What's insecure is allowing an untrusted site to execute javascript on
                    > one's browser. The intended purpose is irrelevant for this. If you
                    > don't yet know this, then you aren't in a position to argue about it.[/color]

                    So ... you're saying that web designers should never use Javascript on the
                    WWW, because the visitors to their websites will end up running these
                    scripts on their browsers.

                    I'm afraid you lost me there. Can you explain how your argument differs
                    logically from the statement that newsagents should never sell matches
                    because people that buy them might set themselves on fire?

                    Perhaps you're confusing "Javascript " with "Java"?

                    Surely you know how to disable Javascript in your browser. So if you're
                    really concerned about this then there's a simple solution. I used to keep
                    it switched off to prevent pop-up ads from appearing, but that was about as
                    bad as it got. Now I have a browser that blocks pup-ups automatically.

                    But to return to the topic of this discussion, the OP's search box is still
                    going to be perfectly usable with Javascript disabled, so nobody's being
                    excluded. Most visitors (i.e., the ones that have Javascript enabled) will
                    see things working as intended. The others will be held up by about 1 second
                    because they will need to delete the pre-filled text. Is that such a big
                    deal?

                    --
                    phil [dot] ronan @ virgin [dot] net



                    Comment

                    • Alan J. Flavell

                      #11
                      Re: Making default entry in search text box disappear on click

                      On Wed, 6 Jul 2005, Philip Ronan wrote:
                      [color=blue][color=green]
                      > > What's insecure is allowing an untrusted site to execute javascript on
                      > > one's browser. The intended purpose is irrelevant for this. If you
                      > > don't yet know this, then you aren't in a position to argue about it.[/color]
                      >
                      > So ... you're saying that web designers should never use Javascript on the
                      > WWW,[/color]

                      No, I'm not saying that. I'm saying that the design should never
                      *rely* on javascript being successfully executed. Using it to provide
                      optional extra conveniences is perfectly fine.

                      Keep in mind, additionally, that none of the indexing robots will be
                      executing your javascript, so anything which *relies* on javascript to
                      reach a particular resource will not get indexed properly.
                      [color=blue]
                      > Perhaps you're confusing "Javascript " with "Java"?[/color]

                      You're very rude.

                      Comment

                      • Philip Ronan

                        #12
                        Re: Making default entry in search text box disappear on click

                        "Alan J. Flavell" wrote:
                        [color=blue]
                        > You're very rude.[/color]

                        I'm sorry you think that way. I'm not *trying* to be rude. I'm just trying
                        to understand your point of view. I'm still confused.

                        You joined this thread by remarking that
                        [color=blue]
                        > What's insecure is allowing an untrusted site to execute javascript on
                        > one's browser. The intended purpose is irrelevant for this. If you
                        > don't yet know this, then you aren't in a position to argue about it.[/color]

                        Then you "clarified" your position by stating that
                        [color=blue]
                        > I'm saying that the design should never
                        > *rely* on javascript being successfully executed. Using it to provide
                        > optional extra conveniences is perfectly fine.[/color]

                        Those viewpoints just aren't consistent. If you check back through this
                        thread, I think you'll find that my suggested solution to the OP's problem
                        doesn't *rely* on the availability of Javascript, because the initial text
                        can easily be deleted by other means. It also provides extra convenience for
                        users by eliminating the need for LABEL and LEGEND elements that might, in
                        some cases, have an adverse effect on the design of a web page.

                        So can you please tell me what I'm doing wrong and why I'm not in a position
                        to comment on this topic?

                        --
                        phil [dot] ronan @ virgin [dot] net



                        Comment

                        • Jukka K. Korpela

                          #13
                          Re: Making default entry in search text box disappear on click

                          Philip Ronan <invalid@invali d.invalid> wrote:
                          [color=blue][color=green]
                          >> Did you have something to say about HTML authoring for the WWW?[/color]
                          >
                          > Sure.[/color]

                          Let's see.
                          [color=blue]
                          > If you want to add a search box to your web pages but you
                          > don't have much space available, here's something you could try:
                          > Create a form with a single INPUT box containing "Search" as the
                          > initial text.[/color]

                          What you should _do_ is to make space, by abandoning wrong ideas about
                          squeezing essential elements into the size of a small stamp. Do, or do
                          not; there is no try.

                          Using "Search" as initial text is simply wrong, since it's defined as
                          _default_ text. It does not solve the space problem. It does not make
                          it clear that it is a search box; it is _not_ a label, but initial
                          content.

                          --
                          Yucca, http://www.cs.tut.fi/~jkorpela/
                          Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

                          Comment

                          • Philip Ronan

                            #14
                            Re: Making default entry in search text box disappear on click

                            "Jukka K. Korpela" wrote:
                            [color=blue]
                            > Philip Ronan <invalid@invali d.invalid> wrote:
                            >[color=green]
                            >> If you want to add a search box to your web pages but you
                            >> don't have much space available, here's something you could try:
                            >> Create a form with a single INPUT box containing "Search" as the
                            >> initial text.[/color]
                            >
                            > What you should _do_ is to make space, by abandoning wrong ideas about
                            > squeezing essential elements into the size of a small stamp. Do, or do
                            > not; there is no try.[/color]

                            I don't recall mentioning postage stamps anywhere. In fact this technique
                            could actually help to free up space so that things *don't* have to be made
                            excessively small. What's wrong with that?
                            [color=blue]
                            > Using "Search" as initial text is simply wrong, since it's defined as
                            > _default_ text.[/color]

                            Where exactly is this definition you're referring to? In the HTML 4.01
                            specification, it says:
                            [color=blue][color=green]
                            >> value = cdata [p.50] [CA] [p.49]
                            >> This attribute specifies the initial value [p.220] of the control.
                            >> It is optional except when the type attribute has the value "radio"
                            >> or "checkbox".[/color][/color]

                            It mentions an "initial value" there, but I can't see the word "default". In
                            case you're interested, all it says on page 220 is:
                            [color=blue][color=green]
                            >> In general, a control's "initial value" may be specified with the
                            >> control element's value attribute.[/color][/color]

                            Again, it doesn't say anything about this being the "default" value.
                            [color=blue]
                            > It does not solve the space problem.[/color]

                            How so?
                            [color=blue]
                            > It does not make it clear that it is a search box;[/color]

                            Just how clear do things have to be? I think anyone with a brain would be
                            able to figure it out. What else do you suppose people might mistake this
                            search box for?
                            [color=blue]
                            > it is _not_ a label, but initial content.[/color]

                            Yes, that's correct. In fact you might like to call it an inventive usage of
                            initial content that eliminates the need for a label. I'm guessing you might
                            not, however :-(

                            --
                            phil [dot] ronan @ virgin [dot] net



                            Comment

                            • Darin McGrew

                              #15
                              Re: Making default entry in search text box disappear on click

                              "Jukka K. Korpela" wrote:[color=blue][color=green]
                              >> it is _not_ a label, but initial content.[/color][/color]

                              Philip Ronan <invalid@invali d.invalid> wrote:[color=blue]
                              > Yes, that's correct. In fact you might like to call it an inventive usage of
                              > initial content that eliminates the need for a label. I'm guessing you might
                              > not, however :-([/color]

                              Rather than using "Search" as the initial content of the text field (and
                              then having to deal with the problems that creates), why not just use
                              "Search" as the label on the submit button? It's clear, it's expected, it's
                              simple, it works for everyone, and it has no unpleasant side effects.
                              --
                              Darin McGrew, mcgrew@stanford alumni.org, http://www.rahul.net/mcgrew/
                              Web Design Group, darin@htmlhelp. com, http://www.HTMLHelp.com/

                              "Cheaters never win; they just finish first." - Johhny Hart

                              Comment

                              Working...