Click here to Skip to main content
15,923,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
I am trying to learn .net with javascript. So i have code a form with validation. but thing is that i want to call that javascript function on lostfocus event of textbox not on button's click event.is any solution for it.

Thank you.
Posted
Updated 14-Nov-11 23:02pm
v2

If you want to do some client side processing, use onblur event and attach a JavaScript handler to it.
For server side processing, you need to handle TextBox's TextChanged event. Do remember to enable AutoPostBack for the TextBox.
 
Share this answer
 
v2
Comments
RaviRanjanKr 15-Nov-11 3:38am    
[Edited]Block quote is removed from normal texts[/Edited]
call ur javascript function on 'onblur' event
 
Share this answer
 
Comments
Param From Mumbai 15-Nov-11 6:49am    
how i will call it on onblur event
Firstly there is no lostfocus event for textbox the same event is called as "onblur". javascript is case sensative so call event properly.
Message on lostfocus

JavaScript
function callMe()
{
if (doument.getElementById("txtValue").value == "")
  {
    alert("Please enter text in textbox");
    return false;
  }
}


call it on lostfocus
JavaScript
<asp:textbox id="cmdCheck" runat="server" onblur="return callMe()" xmlns:asp="#unknown" />
 
Share this answer
 
Comments
Param From Mumbai 15-Nov-11 5:37am    
My javascript function is this ::::


<script language="javascript" type="text/javascript">
function isvalidFirstname() {

var uid;
var temp = document.getElementById("<%=txtname.ClientID %>");
uid = temp.value;
var re = /^[a-zA-Z ]+$/
if (uid == "") {
return ("Please enter firstname" + "\n");
}
else if (re.test(uid)) {
return "";

}
else {
return ("FirstName accepts Characters and spaces only" + "\n");
}
}
</script>

and i am calling it as follow::

<asp:TextBox ID="txtname" runat="server" onblur="return isvalidFirstname()">


but still it not working is there any mistake i have done .....???
Thank you for your solution .i tried so much but i am not able use it into asp.net inline code.is there any solution for it...????/
 
Share this answer
 
Comments
RaviRanjanKr 15-Nov-11 8:28am    
you should use 'Have a Question or Comment' mentioned at the bottom to get quick response.

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