iLTC Home
Bookmark iLTC!
iLTC Google Boards

Google Groups
Receive The Code in Email!



Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • I bookmarked this site...
    123,747

    iLoveTheCode.com
    Javascript > Javascript Tutorials How To Easy > Javascript Reset Form

    Javascript Reset Form



    reset();

    -Use Javascript's built-in reset object.

    The simplest way to use reset would be like this:

    <form name=fori>
    <input type=text name=textfi>
    </form>

    <a href="#" onClick="javascript:document.fori.reset();return false">Clear It!</a>

    -First we created a simple form named fori because we like the name fori.
    -Then we create our link to click on to clear the form.
    -We use Javascript's built-in onClick event handler.
    -Inside the quotation marks we say:
    ---javascript: here comes some javascript
    ---document the page we are on
    ---fori the name we gave our form
    ---reset() Javascript's built-in reset() does the work

    Fairly straight forward. But I am always scared of reset buttons or links because if you have ever filled out a really long form and clicked the wrong button, it can be quite upsetting.

    So let's build a better mousetrap.

    function betterMo() {
    if (confirm("Are you sure you want to clear form?")) {
    document.fori.reset();
    }
    }

    <a href="#" onClick="javascript:betterMo();return false">Clear It!</a>

    This time we created a function to make sure our user wants to clear the form.

    -We used Javascript's built-in confirm method.
    -We enclosed our question in quotation marks.
    -We put our same document.fori.reset() code in the if condtion.
    ---document the page we are on
    ---fori the name we gave our form
    ---reset() Javascript's built-in reset() does the work

    Synopsis: In other words, if the user clicks OK or YES, the form will be reset. Otherwise, the form will be unchanged.


    The code below has three ways to clear the form. The submit button (which will confirm), a confirm link, and an immediately clear link.

    Have fun resetting that form!


    Free Copy and Paste Javascript Code:

    <script type="text/javascript">
    <!--
    function betterMo() {
    if (confirm("Are you sure you want to clear form?")) {
    document.fori.reset();
    }
    }
    -->
    </script>

    <form name=fori>
    <input type=text name=textfi>
    <input type=checkbox name=checki>
    <input type=radio name=radi>
    <textarea name=textai></textarea>
    <input type=submit onClick="betterMo();return false">
    </form>

    <a href="#" onClick="javascript:document.fori.reset();return false">Clear It NOW!</a>
    <a href="#" onClick="javascript:betterMo();return false">Clear It After Confirming</a>

    Resources:
    onClick Javascript
    Javascript Function
    Call a Function in Javascript
    If Else Javascript
    Javascript Alert

    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: Annoy Users with onBlur in Javascript
    Next Article: Javascript Referrer





    New Perspectives on HTML...New Perspectives on HTML and XHTML 5...

    Partrick Carey

    New $67.45

    JavaScriptJavaScript

    David Flanagan

    New $31.49

    HTMLHTML

    Gary B. Shelly, Th...

    New $84.55

    CSSCSS

    David McFarland

    New $23.09

    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.85

    HTML & XHTMLHTML & XHTML

    Chuck Musciano, Bi...

    New $29.99

    Creating Web SitesCreating Web Sites

    Matthew MacDonald

    New $19.77

    CSSCSS

    Eric Meyer

    New $29.69

    HTML, XHTML, and CSS, Si...HTML, XHTML, and CSS, Sixth Edition ...

    Elizabeth Castro

    New $23.09


    Of Interest:
  • Get the Length of a Word or String in Perl
  • To Sort an Array in Perl
  • Matching at the Beginning and End 2
  • If, Elsif, and Else in Perl
  • Javascript Redirect
  • Make Text Blink Using Javascript
  • Javascript SetTimeout
  • Select All or Highlight Text Fields and Textareas Using Javascript
  • Make a New Paragraph Using HTML
  • HTML Underline Text
  • HTML Status
  • HTML Background

  • More Articles:
  • Use chmod in Perl
  • And, Or, Equal, Not Equal, Greater Than, Less Than in Perl
  • Putting Two Strings Together, Concatenate
  • Add to End of an Array with Push in Perl
  • onClick Javascript
  • Javascript Alert
  • Focus a Window with self.focus in Javascript
  • Reading Cookies using Javascript
  • Use onLoad to Call More than One Function with Javascript
  • Passing an Argument or Variable to a Javascript
  • Make Italic Text Using HTML
  • HTML Body Tag
  • HTML Codes
  • Make Strikethrough Text Using HTML

  • Search iLTC w/ Google





    Recent Articles

  • Javascript Focus Form Field
  • Javascript Lowercase Text
  • Javascript Uppercase Text
  • Javascript Superscript Text
  • Javascript Subscript Text
  • Make Text Blink Using Javascript
  • Make a String into a Link in Javascript
  • Javascript Italics Text
  • Javascript Bold Text
  • Javascript Redirect
  • HTML Frames
  • HTML Color Chart
  • HTML Link
  • Javascript Status Bar








  • Perl Programming - Javascript Programming - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006 iLoveTheCode.com


    Contact Chris | About this Site


    420,508
    Counter by iLoveTheCode.com


    Last Modified: Friday, 23-Jun-2006 07:23:15 EDT