Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to set null value in onclick() event of textarea, But my code does not work properly..

ASP.NET
<textarea id="txtwishlistsong1" rows="5" cols="70"  runat="server"  önclick="return txtwishlistsong1_onclick()">Type Your Message Here...</textarea>


code behind:


JavaScript
function txtwishlistsong1_onclick()
   {
      document.getElementById('txtwishlistsong1').focus();
      document.getElementById('txtwishlistsong1').value=null;
   }
Posted
Comments
PrashantSonewane 15-Apr-13 1:16am    
Is this javascript function or C# code? little confused when you said code behind. If your code is at code behind, best way is to assing string.Empty (or '' in case of javascript). And while saving you can check if textwishlistsong1.text / value == string.Empty or '' then insert or send null.

I think problem is in ID of textarea control, your control is marked as runat="server" so its ID will be changed so you should use ClientID property of it to access it in javascript.
 
Share this answer
 
I you want this it on client side then use

<textarea id="txtwishlistsong1" rows="5" cols="70"  runat="server"  önClientclick="return txtwishlistsong1_onclick()">Type Your Message Here...</textarea>


and you function.

If you want this in code-behind then add

txtwishlistsong1.text=string.Empty;
 
Share this answer
 
I am assuming you are trying to write a watermark in your textarea and when there is a click on it you want the watermark text to disappear. It can be done using simple javascript or jquery or AJAX extender

Take a look at following links, hope they help you:

Using jQuery:
Display-Watermark-Text-for-ASPNet-MultiLine-TextArea-using-jQuery-Plugin.aspx[^]

Using Javascript:
how-to-create-watermark-textbox-using-javascript[^]

Using AJAX Extender:
WaterMark Extender[^]

Check link from CP as well:
How to use watermark in asp.net for Textbox[^]
 
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