Tuesday, 9 August 2011

Handling click event for TextBox in asp.net


<script language="javascript" type="text/javascript">
document.onclick = check;  
function check(e)
{
    var target = (e && e.target) || (event && event.srcElement);
    if(target.id!="txt")
    {
        if(document.getElementById("txt").value=="")
        {
            document.getElementById("txt").value="Enter Text Here";
            document.getElementById("txt").style.color='ActiveBorder';
        }
    }
    if(target.id=="txt")
    {
        document.getElementById("txt").style.color="Black";
        if(document.getElementById("txt").value=="Enter Text Here")
            document.getElementById("txt").value="";
    }
}
function Validate()
{
    if(document.getElementById("txt").value!="Enter Text Here" && document.getElementById("txt").value!="")
        return true;
    else
        return false;
}
</script>
<div>
   <asp:TextBox id="txt" runat="server" Text="Enter Text Here"  style="color:ActiveBorder;"></asp:TextBox>
   <asp:Button ID="btn" runat="server" Text="asdf" OnClientClick="javascript:return Validate();" />
</div>

Tag: Handling click event for TextBox in asp.net, text box wrapper event using javascript, textbox events using javascript in asp.net

No comments:

Post a Comment

Parsing JSON w/ @ symbol in it

To read the json response like bellow @ concatenated with attribute                             '{ "@id": 1001, "@name&q...