I have this
$("#formNewsletter").submit(function(){
return false;
})
It works as expected – the form is not submited.
When i write this, it seems like it is returning true (the form is being send)
$("#formNewsletter").submit(function(){
if($("#newsletterSelSpec div").length() > 0)
{
alert("Good");
}
else
{
alert("Please add at least one speciality!");
}
return false;
})
I would like to understand why is this happening and how can I make it work.
Thank you!
the property length isn’t a method.
Use
$("#newsletterSelSpec div").length > 0.You can prevent the default behavior of an event using
preventDefault()witch is a method in the first argument. (event).Not sure, but the problem can be that the alert stops the process of the script and not the submit event.