Reputation: 22323
in jQuery i tried:
$('#imgAdd').live("click", function() {
if ($('#txtName').val() == "") {
$('#lblError').show();
$('#lblError').text() = "Please enter a Name";
$('#txtMenuName').focus();
}
return false;
}
but i got a error in console.
invalid assignment left-hand side
$('#lblError').text() = "Please enter a Menu Name";
I also want if text is entered in field automatically lblerror
is hide. How do I achieve this?
Upvotes: 0
Views: 65
Reputation: 35822
Use:
$('#lblError').text("Please enter a Menu Name");
text()
function is both a getter and a setter function. Thus, if you call it without parameters, you get the current text of the HTML element. But if you pass a parameter to it, you set the text of the HTML element.
For hiding the error message, when user enters text into textbox, you can use keyup
event handler of jQuery:
$('#txtName').keyup(function(e){
if($(this).val().length > 0) {
$('#lblError').hide();
}
});
Upvotes: 3