www.webdeveloper.com
Results 1 to 3 of 3

Thread: Clear function

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    4

    Clear function

    Want to make a function to clear a text box using a button.

    Here is what I have so far:

    HTML:

    <button onclick="clear()">Clear</button>

    <form name="myForm1">
    <textarea rows="4" cols="50" id="myTextArea" name="myTextArea">
    </textarea>
    </form>

    JavaScript:

    function clear() {
    document.myForm1.myTextArea.value ="";
    }


    I don't really know what i'm doing if i'm honest. Is this close to what i need to do? I have to use JavaScript.

    Thanks!

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330

    Lightbulb

    change the name in the form tag to id

    then modify the clear function to
    document.getElementById('myForm1').myTextarea.value='';

  3. #3
    Join Date
    Dec 2012
    Location
    NSW Australia
    Posts
    73
    change your clear() function name to something else...

    EG clearME()

    and also in the button onclick....

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles