September 30, 2012
How will I compare a text input if it is empty or not?
Question by eggshot
How will I compare a text input if it is empty or not inside a Jquery statement? Is the code below alright?
$(#'generate').click(function(){
if(parseInt($('#lastname').val,10)==0){
alert("Should Not Be Empty!");
}
}
Answer by Starx
Simply
$('#generate').click(function(){
if($('#lastname').val().trim() != "") {
alert("Should Not Be Empty!");
}
}
Also, there is a typo
$(#'generate').click(function(){
// ^ Right here