Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    25
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation Clear a textarea using javascript

    I am looking for a javascript that when a image is clicked on it clears a textarea

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,733
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Here you are:-

    Code:
    <textarea id = "txt1" rows = "6" cols = "24">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>

    A man ceases to be a beginner in any given science and becomes a master in that science when he has learned that he is going to be a beginner all his life. Robin G. Collingwood (English Philosopher, 1889-1943)

  • #3
    New Coder
    Join Date
    Sep 2009
    Posts
    25
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Smile

    Thanks peter and your very good using javascript

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,733
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    My name is Philip, not Peter.

  • #5
    New Coder
    Join Date
    Sep 2009
    Posts
    25
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Smile

    Im really sorry i am always in a rush sorry

  • #6
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Philip,

    After passing values, I erased the textarea to start over and tried passing a new value but the previous values return with the new value. Can you help me?

    <script type = "text/javascript">
    function eraseText() {
    document.getElementById("a_gent").value = "";
    }
    </scrip

    note that I have a function to pass the value into textarea.

    <SCRIPT LANGUAGE="JavaScript">
    oldvalue = "";
    function passText(passedvalue) {
    if (passedvalue != "") {
    var totalvalue = passedvalue+"\n"+oldvalue;
    document.parentForm.dueagent.value = totalvalue;
    oldvalue = document.parentForm.dueagent.value;
    }
    }
    </script


    thank you in advance!!
    Last edited by jorgeftz; 06-06-2010 at 06:11 PM.

  • #7
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    Philip, this is an old thread, but I've got the same problem and the solution isn't working for me. Here is my code:
    Code:
    function resetStuff()
    {
     document.getElementById("inputText").value = "";
     debug.innerHTML = "";
     display.innerHTML = "Display: ";
     testing.innerHTML = "";
    }
    The problem may be in the execution - I'm doing it here:
    Code:
    <body onload("resetStuff()")>
    The assumption I'm making is hitting "F5" on the page will trigger the onload event. This doesn't seem to happen and therefore the routine isn't called (and the textarea doesn't get reset.

    Assuming the code is OK (maybe a big assumption), is there a different event I should be hooking this into?
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,733
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    <body onload = "resetStuff()">


    debug.innerHTML = "";
    If debug is an element you must use document.getElementById("debug").innerHTML = "";

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 06-13-2013 at 05:17 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    jerry62704 (06-13-2013)

  • #9
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    That's why you are the man and I'm just a tired old coot. And my wife of 40 years would agree, too.
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls


  •  

    Posting Permissions

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