How is the "check" made for this to check if a textfield is empty?
Jquery:
$("#AddGoogleMap").click(function () {
if($('#googleMapCity').val()==null) {
alert("You need to fill out a city");
} else {
// do something
}
First, remove the whitespace from the beginning and end of a string and then compare the value with the empty string, like:
if( $.trim($('#googleMapCity').val()) === '') {
alert("You need to fill out a city");
} else {
// do something
}
$("#AddGoogleMap").click(function () {
if($('#googleMapCity').val() === "") {
alert("You need to fill out a city");
} else {
// do something
}
});
$('#googleMapCity').val()===''or$('#googleMapCity').val().length===0.empty()removes the content and any nested DOM element.