Click here to Skip to main content
15,910,130 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to this type of code
my html has one textarea i want to clear text when it clicked my clear function in the external JavaScript file in same directory
my code like this where the wronge code is

html file

HTML
<!DOCTYPE html>
<html>
<head>
<script src="clear.js"></script>
</head>
<body>
<br />
<br />

<textarea onkeyup= "changetext();" onselect="changetext();" onclick="changetext();"  önfocus="changetext();" style="font-size: 12pt;
                            width: 500px;" name="box1" rows="7">description here</textarea>
                        
  </body>                     
</html>


my JavaScript file like this

JavaScript
function changetext()
{
if(this.value=='description here') this.value='';
}
Posted
Updated 4-May-14 21:53pm
v2
Comments
thatraja 5-May-14 4:03am    
any error? check debugger(firebug or anything else)
Peter Leow 5-May-14 4:21am    
Just curious, do you just want to clear the initial text, i.e. 'description here' which is default when the user start typing into it the textarea? If that is the case, you can add a placeholder attribute inside the textarea tag. no need javascript.

Pass ID of the Textbox control as parameter to that javascript function, IT will solve your problem
 
Share this answer
 
Try this

C#
function changetext()
{
if(box1.value=='description here') this.value='';
}
 
Share this answer
 
Could you try like this:

HTML
HTML
<textarea onkeyup="changetext(this);" onselect="changetext(this);" onclick="changetext(this);" önfocus="changetext(this);" style="font-size: 12pt;<br mode=" hold=" />                            width: 500px;" name="box1" rows="7">description here</textarea>


Javascript
JavaScript
function changetext(obj)
{
 if(obj.value=='description here') this.value='';
}


also check the path of your external javascript file is correct or not(just drag n drop it from the solution explorer to the html page.)
 
Share this answer
 
JavaScript:
JavaScript
function changetext(element) {
  if(element.value=='description here') element.value='';
}

HTML:
HTML
<textarea onkeyup="changetext(this);" onselect="changetext(this);" onclick="changetext(this);" onfocus="changetext(this);" style="font-size: 12pt;<br mode=" hold=" />                            width: 500px;" name="box1" rows="7">description here</textarea>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900