Results 1 to 5 of 5

Thread: using javascript how to clear text area?

  1. #1
    Join Date
    Jul 2013
    Posts
    95

    using javascript how to clear text area?

    I have recently started learning Javascript and I was having some questions on this particular programming language. Can anyone tell me how do I clear the value on the text area by clicking on it? I know what to use that is - onclick="function_name" but I dont know how to put everything together, like what all things should be inside the value and all? Can anyone please explain? Thanks.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: using javascript how to clear text area?

    Check the below onclick even handler to the textarea opening tag if you want to do it that way:

    Code:
    <textarea onclick="this.value=''; ">
    Also, if you want to clear the textarea then you can click on a seperate button like the below html code:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <script  type="text/javascript">
    function cleatTextAtea() {
    document.getElementById("txtArea").value='';
    }
    </script>
    
    </head>
    <body>
    <textarea id="txtArea" cols="40" rows="5">Enter text here....</textarea>
    <button onclick="cleatTextAtea();">Clear Textarea</button>
    </body>
    </html>

  3. #3
    Join Date
    May 2009
    Posts
    529

    Re: using javascript how to clear text area?

    If you want a javascript that when a image is clicked on it then it should be clearing a textarea, then check the below code:

    Code:
    <textarea id = "txt1" rows = "4" cols = "16">Content of textarea</textarea>
    <br><br>
    
    <img src = "one.gif" alt ="" title = "" onclick = "eraseText()">
    
    <script type = "text/javascript">
    function eraseText() {
    document.getElementById("txt1").value = "";
    }
    </script>

  4. #4
    Join Date
    May 2009
    Posts
    511

    Re: using javascript how to clear text area?

    By using javascript you can erase or delete any text in the textarea, just check the below example where a textarea element is created that contains some text

    Code:
    <html>
    <head>
    <title>javascript focus input</title>
    <script type="text/javascript">
    
    function clearTextArea() {
    document.textform.textarea.value='';
    }
    
    </script>
    </head>
    <body>
    <form name="textform">
    <textarea name="textarea">
    This text will be removed if you click on 'Clear TextArea' button.</textarea>
    </form>
    
    <input type="button" id="name" onClick="clearTextArea();" value="Clear TextArea" /><br>
    
    </body>
    </html>

  5. #5
    Join Date
    Jan 2014
    Posts
    7

    Re: using javascript how to clear text area?

    if(document.textform.textarea.value == 'GARBAGE_VALUES'){

    document.textform.textarea.value =";

    }

    plain and simple. just check if it has garbage values then clear it.

Similar Threads

  1. Resize any text area in Firefox
    By Computer_Freak in forum Tips & Tweaks
    Replies: 4
    Last Post: 19-11-2011, 04:04 AM
  2. How to recover lost text from text area in Google Chrome?
    By Corwinn in forum Technology & Internet
    Replies: 5
    Last Post: 10-03-2010, 12:56 PM
  3. How to Reset or Clear a form using JavaScript?
    By SKREECH in forum Software Development
    Replies: 4
    Last Post: 07-02-2010, 06:50 AM
  4. Text area problem
    By Ameeryan in forum Software Development
    Replies: 3
    Last Post: 13-11-2009, 12:23 PM
  5. how to do highlight text area in html
    By Shanbaag in forum Software Development
    Replies: 3
    Last Post: 30-07-2009, 02:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,665,171,792.85543 seconds with 17 queries