0

"What I am trying to achieve is onclick will remove the text within a textbox".

I read some answers from this site which someone is using "function pageLoad(sender, args)" javascript but the problem is that on debug using Firefox break point the function line doesn't stop on it. Am I missing a loaded up javascript requirement from microsoft or something else? here is my test code.

    function pageLoad() {
        $("#<%=Text_Message.ClientID%>").click(function () {
            alert("Handler for .click() called.");
        });
    }
    $(document).ready(function () {
        $("#<%=Text_Message.ClientID%>").click(function () {
            alert("Handler for .click() called.");
        });
    });

textbox

<asp:TextBox ID="Text_Name" runat="server" CssClass="" Width="234px" >Name</asp:TextBox>
3
  • 1
    For one, it should be <%=Text_Name.ClientID%> based on your example Commented Aug 14, 2012 at 14:45
  • Why don't you use classes? It will be much easier !!! jsfiddle.net/3Pg8F Commented Aug 14, 2012 at 14:59
  • I am still learning server side html and normal html. Commented Aug 14, 2012 at 15:03

1 Answer 1

2

use focus instead of click on textbox and empty its text using $(this).val("");

Live Demo

$(document).ready(function () {
        $("#<%=Text_Message.ClientID%>").focus(function () {
            alert("Handler for .click() called.");
            $(this).val("");
        });
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.