I have a form containing some values like firstname, lastname, etc. When i am not filling all the details, i have displayed the text please fill all the details and it goes to the next step in jquery . I dont want it to go to the next step.
$("button.info").click(function(event){
var fnamee = $('input.firstname').val();
var lnamee = $('input.lastname').val();
if(fnamee==''||lnamee=='')
{
alert("Please Fill All Fields");
event.preventDefault();
}
else{
}
});
my form is :
<form>
<input type="text" class="fname"/>
<input type="text" class="lname"/>
<input type="submit" class="info" name="submit"/>
</form>
I have given the preventDefault but it is not working.
Can anyone tell a solution for this ?
$("button.info")this is wrong. It should be$(".info")as input is of type submit