Click here to Skip to main content
15,850,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
in on blur() event i have used jquery for validation . If validation occurs the text box color should change and the cursor should be on the same text box . I have used focus() for this , but it is not working. Can you help me on this ?

<asp:TextBox ID="txtMemoName" runat="server" Width="200px" onblur="alertevent();" ></asp:TextBox>

function alertevent() {
            var value = $("#<%=txtMemoName.ClientID %>").val();
            if (value == "") {
		 $("#<%=txtMemoName.ClientID %>").focus();
		 $("#<%=txtMemoName.ClientID %>").css('border', '1px solid red');
JR009 17-Nov-14 2:19am    
hey, can you get txtMemoName textbox text in value variable?
januskarthik 17-Nov-14 2:21am    
yes, i got textbox text in value variable..
JR009 17-Nov-14 2:34am    
Ok, then try using javascript like document.getElementById("<%=txtMemoName.ClientID %>").focus(); and also add one more line : $("#<%=txtMemoName.ClientID %>").css('display', 'inline');
januskarthik 17-Nov-14 4:46am    
not working jignesh

1 solution

In general you should return false from the validation and use onblur="return alertevent();" which will prevent further propagation of the event.

If this helps please take time to accept the solution. Thank you.
Share this answer
januskarthik 17-Nov-14 4:15am    
its does't change anything
Sinisa Hajnal 17-Nov-14 4:35am    
Could you update the code in the question with what you've done?
januskarthik 17-Nov-14 4:51am    
<asp:TextBox ID="txtMemoName" onblur="return alertevent();" runat="server" Width="200px" >

function alertevent() {
var value = $("#<%=txtMemoName.ClientID %>").val();
if (value == "") {
$('#<%=txtMemoName.ClientID %>').focus();
$("#<%=txtMemoName.ClientID %>").css('border', '2px solid red');
return false;
Mathew Soji 17-Nov-14 4:50am    
My +5
Sinisa Hajnal 17-Nov-14 6:07am    
Thank you.

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