Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi....
I want to to know,when my cursor move from one textbox to another textbox,
If you did not value in textbox1 then a validation should work using jquery
Posted
Comments
Thomas Daniels 28-Feb-14 12:38pm    
So, if I understand you correctly, you want to test whether textbox1 is empty when focusing another textbox, is that correct?
1989priya 28-Feb-14 12:43pm    
yaa.....like that.I tell you through a example.
Suppose you have 2 textbox.In first textbox you will have to fill email and 2 textbox will fill name.when your focus out from one textbox to another textbox.Fisrt textbox should print a validation message i.e. please filled a email

1 solution

If I understand you correctly, you want to test whether textbox1 is empty if you focus another textbox. Then try this:
JavaScript
$('#textbox2').focus(function() {
    if ($('#textbox1')[0].value.trim() === '') {
        alert('Textbox1 is empty');
    }
});

Note that this also says that textbox1 is empty if it only contains whitespace. If you consider whitespace a valid value of textbox1, then just remove the .trim() from the code.

Test online: http://jsfiddle.net/ProgramFOX/wXqqR/[^]

[EDIT]

In your comment, you said that you want to validate instead of checking like I did. Then, try to trigger validation:
JavaScript
$('#textbox2').focus(function() {
    if ($('#yourForm').validate().element('#textbox1')) {
        // #textbox1 is valid
    }
});
 
Share this answer
 
v5
Comments
1989priya 28-Feb-14 12:58pm    
No...I dont want this.I want a validation.I show you my coding...
$(document).ready(function () {
$("#form1").validate(
{
rules:
{
'<%=TextBox1.UniqueID %>':
{
required: true
}

},
messages:
{
'<%=TextBox1.UniqueID %>':
{
required:"Please enter name"
}
}
});


});



that coding work correctly but it work after click on button but I want this should be show focus go on from textbox to another textbox
Thomas Daniels 28-Feb-14 13:05pm    
I updated my answer.
1989priya 28-Feb-14 13:12pm    
thankx.....it work f9
I give you my 5
Thomas Daniels 28-Feb-14 13:15pm    
You're welcome!
1989priya 28-Feb-14 13:41pm    
can you please tell if I have to show a message of validation on a label than how will be show??

I am not more familiar in jquery.

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