If I understand you correctly, you want to test whether
textbox1
is empty if you focus another textbox. Then try this:
$('#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:
$('#textbox2').focus(function() {
if ($('#yourForm').validate().element('#textbox1')) {
}
});