Clear textarea onclick of image

J

Jake

How can I have an image that when clicked would clear my textarea field?

The textarea field is the only element in my form and has a default value -
a couple lines of text..
I tried using a reset button but it only clears text that was just entered.

TIA!
 
I

Ivo

How can I have an image that when clicked would clear my textarea field?

The textarea field is the only element in my form and has a default value -
a couple lines of text..
I tried using a reset button but it only clears text that was just
entered.

Yes, the reset() method of forms returns all input elements to their default
values. In case you supply your own default value, this is what will be
used. To empty the element you then need to explicitly forward an empty
string, such as the pair of single quotes in the following:

<img src="..." width="..." height="..." alt=" Clear the textarea! "
onclick="document.forms.FORMNAME.elements.TEXTAREANAME.value=''; "

hth
 
J

Jake

Ivo said:
entered.

Yes, the reset() method of forms returns all input elements to their
default
values. In case you supply your own default value, this is what will be
used. To empty the element you then need to explicitly forward an empty
string, such as the pair of single quotes in the following:

<img src="..." width="..." height="..." alt=" Clear the textarea! "
onclick="document.forms.FORMNAME.elements.TEXTAREANAME.value=''; "

hth

Perfect - Thanks!
 
M

McKirahan

Jake said:
How can I have an image that when clicked would clear my textarea field?

The textarea field is the only element in my form and has a default value -
a couple lines of text..
I tried using a reset button but it only clears text that was just entered.

TIA!

If you want to stay with buttons:

<html>
<head>
<title>clear.htm</title>
</head>
<body>

<form name="form1">
<textarea name="area" cols="40" rows="4">Hello World</textarea>
<br><br>
<input type="reset" value="Reset">
<input type="button" value="Clear" onclick="document.form1.area.value=''">
</form>

</body>
</html>

Note that
.value=''"
is typed as
".value=" + apostrophe + apostrophe + quotation mark
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top