Click here to Skip to main content
15,909,437 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have Textbox-A and Textbox-B. Textbox-A is mandatory.

If a user comes to Textbox-A and without entering anything if he moves to next available control (Textbox-B) either by tabbing or by moving the cursor,

error message should be displayed.

Could anyone of you please help me by telling in which event to write the validation.



Looking forward to hear from you ASAP.
Posted

Try this!!
XML
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction(obj)
{

if(obj.value=="")
{
alert("Please enter Value");
}
else{
obj.value=obj.value.toUpperCase();
}
}
</script>
</head>
<body>

Enter your name 1: <input type="text" id="fname1" onblur="myFunction(this)"></br>
Enter your name 2: <input type="text" id="fname2" onblur="myFunction(this)"></br>
Enter your name 3: <input type="text" id="fname3" onblur="myFunction(this)"></br>
<p>When you leave the input field, a function is triggered which transforms the input text to upper case.</p>

</body>
</html>
 
Share this answer
 
Comments
Avik Ghosh22 26-Feb-13 0:46am    
nice.. 5!.
XML
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True"
                    ontextchanged="TextBox2_TextChanged"></asp:TextBox>




C#
protected void TextBox2_TextChanged(object sender, EventArgs e)
   {
       if (TextBox1.Text == "")
       {
           Response.Write("enter value in textbox1!");
           TextBox2.Text = "";
       }
       else
       {
       }
   }
 
Share this answer
 
v2
Hi If you are using asp.net web application then you should use

OnBlur event when user lose control focus we need to write javascript validation to check whether textbox1 is emepty or not.
If you need code let me know


If you are using Window application then in Textbox control we have event of LostFocus
 
Share this answer
 

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