Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="/css/total.css" rel="stylesheet" type="text/css" />
<script src="../jquery/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
 
    }
 
    $("#txtsvalue").focus(function () {
        alert("working well");
    });
</script>
 
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


I wrote the following jquery to when Textbox "txtsvalue" focused then it shows the alert. But it does not work.
Thanks in advance to help.
Posted
Updated 21-Sep-14 23:56pm
v2

fiddle for this[^]
Please check the above fiddle. On focus the alert pops up. Hope this helps.
Thanks
Happy Coding
:)
 
Share this answer
 
v4
Comments
Thanks7872 22-Sep-14 5:20am    
Verify the link you have posted.
[no name] 22-Sep-14 5:46am    
thanks and sorry I have changed now. Misplaced the url.:)
Thanks7872 22-Sep-14 5:58am    
I corrected Now.
Change the javascript like the below one.
JavaScript
<script src="../jquery/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () { 
    $("#txtsvalue").focus(function () {
        alert("working well");
    });
});
</script>


Hope the above solution helps.
 
Share this answer
 
v2
Comments
Sumon562 22-Sep-14 4:13am    
Thanks a lot Mr. ChauhanAjay. But it does not work
ChauhanAjay 22-Sep-14 4:19am    
Try adding this to your textbox in asp.net ' ClientIDMode="Static"'. JQuery can then recognize your textbox. Kindly try and let me know the result.
Sumon562 22-Sep-14 5:28am    
Still it does not work
Sinisa Hajnal 22-Sep-14 4:28am    
If you have asp:TextBox you have to get ClientID from the server (See my improved solution)
ChauhanAjay 22-Sep-14 5:00am    
I have given that solution basing on Mohi Uddin's script.
Put your function in document ready function. In the code above, maybe the function executes before txtsvalue is available so the handler is never attached. Fire up some debugger, open Console tab and see if you get object "txtsvalue" is null...

Try this:

JavaScript
$(document).ready (function() {
    $("#<%=txtsvalue.ClientID%>").focus(function () {
        alert("working well");
    });
});


Or better yet:
JavaScript
$(document).ready (function() {
    $("your-container").on("focus", "#txtsvalue", function () {
        alert("working well");
    });
});


in this code, "your-container" should be any parent of txtsvalue that is common to all controls you need this functionality for (may be even document) - if you need some other control added later, simply change the selector part "#txtsvalue, #txtSomeOtherControl". Classes, pseudo-classes, tags...any element creating valid jQuery selector can go there and all those elements will have the same focus function.

If this helps, please take some time to accept the solution so others may find it. Thank you.
 
Share this answer
 
v3
Comments
Sumon562 22-Sep-14 5:27am    
It shows the following error :
Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1002: ; expected
Sinisa Hajnal 22-Sep-14 6:09am    
That is something in your code-behind, javascript is not compiled like that.

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