Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Clear a field in a form

Reply
Thread Tools

Clear a field in a form

 
 
Bob Sanderson
Guest
Posts: n/a
 
      04-18-2007
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.
 
Reply With Quote
 
 
 
 
shimmyshack
Guest
Posts: n/a
 
      04-18-2007
On Apr 18, 9:19 pm, Bob Sanderson <(E-Mail Removed)>
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';ret urn 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.

 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      04-18-2007
shimmyshack said:
>
>On Apr 18, 9:19 pm, Bob Sanderson <(E-Mail Removed)>
>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';re turn 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.


--

 
Reply With Quote
 
shimmyshack
Guest
Posts: n/a
 
      04-19-2007
On Apr 19, 12:21 am, Lee <(E-Mail Removed)> wrote:
> shimmyshack said:
>
>
>
>
>
> >On Apr 18, 9:19 pm, Bob Sanderson <(E-Mail Removed)>
> >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';re turn 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to retrieve form field value if form is EncType=multipart/form-dataForm? Li Zhang ASP .Net 4 02-27-2009 01:23 AM
Clear form field? Garry Jones Javascript 1 10-08-2006 10:26 PM
Pass hidden form field value to another form field to insert in db GavMc ASP General 4 09-22-2005 06:33 PM
copy and paste form RTF document into field in asp form cause it to bypass field length and javascript validation - how to overcome? NotGiven Javascript 3 05-13-2004 12:15 AM
copy and paste form RTF document into field in asp form cause it to bypass field length and javascript validation - how to overcome? NotGiven ASP General 3 05-13-2004 12:15 AM



Advertisments