Home > ASP.NET, javascript > Water marking for asp:textbox using javascript

Water marking for asp:textbox using javascript

A while ago i had a task to implement water mark on asp:textbox , well a short one but its always good to have the tasks which are not done before as they provides room for improvement and learning. In my opinion its not bad to learn even a single character a day .

Simple javascript function to deal in.

<script
type=”text/javascript”
language=”javascript”>
function
clearWaterMark()
{


var text = document.getElementById(‘<%=txtExample.ClientID %>’).value;


if(text.match(“^Example”))

{

document.getElementById(‘<%=txtExample.ClientID %>’).value= ;

}

}

function addWaterMark()

{ if(document.getElementById(‘<%= txtExample.ClientID %>’).value== )

{

document.getElementById(‘<%= txtExample.ClientID %>’).value=“Example C:\\FileName.p12”;

}

}
</script>

 

<asp:TextBox
ID=”txtExample”
Width=”233px”
runat=”server”
Font-Size=”XX-Small”
ToolTip=”Type full path of certificate including extention.”
onClick=”clearWaterMark()”
onBlur=”addWaterMark()”>Example C:\Certificate.p12</asp:TextBox>

 

Javascript functions are called on events

  • onClick=”clearWaterMark()”
    //Checks if there is text in textbox starting with “Example” then clearing that.
  • onBlur=”addWaterMark()” // Checkis if there is no text in textbox then adding the text to textbox

 

Happy Coding J

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: