I made a small form and I want it to send information back to the user when the inputs are left blank.
For some reason, he says use post request, so I added it, and now it gives me another error message.
Here is the code: http://jsfiddle.net/pwtnY/
<div id="main"> <form name="myForm" method="post"> <label><span>First Name:</span><input type="text" class="firstname" name="fname"></label><br/> <label><span>Last Name:</span><input type="text" class="lastname"></label><br> <label><span>E-Mail:</span><input type="text" class="email"></label><br/> <label><span>Phone:</span><input type="text" class="phone"></label><br/> <input type="submit" name="submit"> </form> <div id="answer"></div> </div>
JavaScript:
$(document).ready(function(){ $('input:submit').click(function(){ $firstname = $('.firstname').val(); $lastname = $('.lastname').val(); $email = $('.email').val(); $phone = $('.phone').val(); if($firstname === "" && $lastname==="" && $email ==="" && $phone === ""){ $("#answer").html("Please fill out all fields."); } }); });
Does anyone know what could be the problem and how can I solve it?
source share