Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23-08-2013
Member
 
Join Date: Jul 2013
Posts: 90
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.
Reply With Quote
  #2  
Old 24-08-2013
Member
 
Join Date: May 2008
Posts: 2,293
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>
Reply With Quote
  #3  
Old 26-08-2013
Member
 
Join Date: May 2009
Posts: 525
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>
Reply With Quote
  #4  
Old 27-08-2013
Member
 
Join Date: May 2009
Posts: 503
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>
Reply With Quote
  #5  
Old 03-02-2014
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 06:25 PM.