Clear a field in a form

B

Bob Sanderson

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.
 
S

shimmyshack

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.
 
L

Lee

shimmyshack said:
<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.


--
 
S

shimmyshack

shimmyshack said:












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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top