implement clear function using reset button

M

Matt

i need to implement a clear button to clear all the fields in the
form,
but i am thinking i can just use reset button.

<input type="reset" name="reset" value="CLEAR">

The first thought is that if there is default value reset and clear
will become different.
My understanding is that reset means to restore the original page
before
any edits by the user.

It seems like I can use reset button to implement clear javascript
button.

Please advise. Thanks!!
 
S

Steven Daedelus

i need to implement a clear button to clear all the fields in the
form,
but i am thinking i can just use reset button.

<input type="reset" name="reset" value="CLEAR">

The first thought is that if there is default value reset and clear
will become different.
My understanding is that reset means to restore the original page
before
any edits by the user.

It seems like I can use reset button to implement clear javascript
button.

Please advise. Thanks!!

I can't really help you on this, but I thought I'd ask the group a more
general question:

Do you include a clear button in your forms? Why? Who would fill out a
whole form and then decide they want to clear it?
 
T

Thomas 'PointedEars' Lahn

Matt said:
i need to implement a clear button to clear all the fields in the
form, but i am thinking i can just use reset button.

<input type="reset" name="reset" value="CLEAR">

The first thought is that if there is default value reset and clear
will become different.
My understanding is that reset means to restore the original page
before any edits by the user.

That button sets the default value for all form elements of the form.
It seems like I can use reset button to implement clear javascript
button.

It doesn't, and you shouldn't. Instead, you should use something like
the following.

J(ava)Script:

function clearForm(o)
{
if (o && o.form)
{
o = o.form;
}

var e;
if (o && (e = o.elements))
{
for (var i = 0; len = e.length, tn, ty; i < len; i++)
{
o = e;
if ((tn = o.tagName)
&& (ty = o.type)
&& ((tn = tn.toLowerCase()) == "input"
&& ty.toLowerCase() == "text")
|| tn == "textarea")
{
o.value = "";
}
}
}
}

HTML

<form ...>
...
<input type="button" value="Clear" onclick="clearForm(o)">
...
</form>


HTH

PointedEars
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top