Clear a field in a form

Discussion in 'Javascript' started by Bob Sanderson, Apr 18, 2007.

  1. I need a JavaScript that will allow me to clear a field in a form when I
    click an image next to it.

    Any help will be greatly appreciated.
    Bob Sanderson, Apr 18, 2007
    #1
    1. Advertising

  2. Bob Sanderson

    shimmyshack Guest

    On Apr 18, 9:19 pm, Bob Sanderson <>
    wrote:
    > I need a JavaScript that will allow me to clear a field in a form when I
    > click an image next to it.
    >
    > Any help will be greatly appreciated.


    <input
    type="text"
    accesskey="s"
    maxlength="50"
    class="purplepic"
    id="q"
    name="q"
    onblur="if(this.value=='')this.value='click here search our
    site...';this.className='purplepic';"
    onfocus="if(this.value=='click here search our
    site...')this.value='';this.className='redpic';return true;"
    value="click here search our site..."
    />

    <a
    title="click here to clear the search box"
    id="reset"
    href="javascript:void(0);"
    onclick="clearit();return false;">
    </a>

    use a style sheet to style the link, or use an image with the onclick
    instead.

    here's the javascript:

    function clearit()
    {
    var panel = document.getElementById('q');
    panel.value='';
    panel.focus();
    }

    Randy will hate this cos it uses gebi, but hey! And this is just a
    copy and paste job from 2004, there are more "modern" unobtrusive
    methods to do this, left as an exercise for the OP.
    shimmyshack, Apr 18, 2007
    #2
    1. Advertising

  3. Bob Sanderson

    Lee Guest

    shimmyshack said:
    >
    >On Apr 18, 9:19 pm, Bob Sanderson <>
    >wrote:
    >> I need a JavaScript that will allow me to clear a field in a form when I
    >> click an image next to it.
    >>
    >> Any help will be greatly appreciated.

    >
    ><input
    > type="text"
    > accesskey="s"
    > maxlength="50"
    > class="purplepic"
    > id="q"
    > name="q"
    > onblur="if(this.value=='')this.value='click here search our
    >site...';this.className='purplepic';"
    > onfocus="if(this.value=='click here search our
    >site...')this.value='';this.className='redpic';return true;"
    > value="click here search our site..."
    >/>
    >
    ><a
    > title="click here to clear the search box"
    > id="reset"
    > href="javascript:void(0);"
    > onclick="clearit();return false;">
    ></a>
    >
    >use a style sheet to style the link, or use an image with the onclick
    >instead.
    >
    >here's the javascript:
    >
    >function clearit()
    >{
    > var panel = document.getElementById('q');
    > panel.value='';
    > panel.focus();
    >}
    >
    >Randy will hate this cos it uses gebi, but hey! And this is just a
    >copy and paste job from 2004, there are more "modern" unobtrusive
    >methods to do this, left as an exercise for the OP.


    I can't speak for Randy, but it's lousy code.
    You abuse a link just for a side-effect and then use the least
    efficient way to access the field.


    --
    Lee, Apr 19, 2007
    #3
  4. Bob Sanderson

    shimmyshack Guest

    On Apr 19, 12:21 am, Lee <> wrote:
    > shimmyshack said:
    >
    >
    >
    >
    >
    > >On Apr 18, 9:19 pm, Bob Sanderson <>
    > >wrote:
    > >> I need a JavaScript that will allow me to clear a field in a form when I
    > >> click an image next to it.

    >
    > >> Any help will be greatly appreciated.

    >
    > ><input
    > > type="text"
    > > accesskey="s"
    > > maxlength="50"
    > > class="purplepic"
    > > id="q"
    > > name="q"
    > > onblur="if(this.value=='')this.value='click here search our
    > >site...';this.className='purplepic';"
    > > onfocus="if(this.value=='click here search our
    > >site...')this.value='';this.className='redpic';return true;"
    > > value="click here search our site..."
    > >/>

    >
    > ><a
    > > title="click here to clear the search box"
    > > id="reset"
    > > href="javascript:void(0);"
    > > onclick="clearit();return false;">
    > ></a>

    >
    > >use a style sheet to style the link, or use an image with the onclick
    > >instead.

    >
    > >here's the javascript:

    >
    > >function clearit()
    > >{
    > > var panel = document.getElementById('q');
    > > panel.value='';
    > > panel.focus();
    > >}

    >
    > >Randy will hate this cos it uses gebi, but hey! And this is just a
    > >copy and paste job from 2004, there are more "modern" unobtrusive
    > >methods to do this, left as an exercise for the OP.

    >
    > I can't speak for Randy, but it's lousy code.
    > You abuse a link just for a side-effect and then use the least
    > efficient way to access the field.
    >
    > --


    javascript when it isnt used unobtrusively is indeed an abuse; as is
    buffing one's own ego while sitting on the other hand.
    shimmyshack, Apr 19, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David

    Response.Clear() doesn't clear

    David, Jan 31, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    995
    Mark Fitzpatrick
    Jan 31, 2008
  2. NotGiven
    Replies:
    3
    Views:
    331
    Michael D. Kersey
    May 13, 2004
  3. GavMc
    Replies:
    4
    Views:
    311
    Evertjan.
    Sep 22, 2005
  4. NotGiven
    Replies:
    3
    Views:
    290
    Michael D. Kersey
    May 13, 2004
  5. Garry Jones

    Clear form field?

    Garry Jones, Oct 8, 2006, in forum: Javascript
    Replies:
    1
    Views:
    99
    McKirahan
    Oct 8, 2006
Loading...

Share This Page