implement clear function using reset button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt

    #1

    implement clear function using reset button

    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!!
  • Steven Daedelus

    #2
    Re: implement clear function using reset button

    In article <ba8a039e.04052 71513.5d7606d1@ posting.google. com>,
    jrefactors@hotm ail.com (Matt) wrote:
    [color=blue]
    > 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!![/color]

    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?

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: implement clear function using reset button

      Matt wrote:
      [color=blue]
      > 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.[/color]

      That button sets the default value for all form elements of the form.
      [color=blue]
      > It seems like I can use reset button to implement clear javascript
      > button.[/color]

      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="clearF orm(o)">
      ...
      </form>


      HTH

      PointedEars

      Comment

      Working...