By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,409 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

implement clear function using reset button

P: n/a
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!!
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <ba**************************@posting.google.com >,
jr********@hotmail.com (Matt) wrote:
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?
Jul 23 '05 #2

P: n/a
Matt wrote:
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[i];
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
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.