jquery - Prevent form submit if field value is false -
jquery - Prevent form submit if field value is false -
i trying create code utilize jquery prevents users submitting form if value in text field different 50. form submit work great, having issues jquery code prevent submitting.
my html code:
<form name="vehicleregfrm" id="vehicleregfrm" action="" method="post"> <input name="samp" id="samp" type="text" /> <input name="sbtaddcarfrm" type="submit" value="continue" /> </form>
here problematic jquery code:
$('sbtaddcarfrm').on('click', function(event) { event.preventdefault ? event.preventdefault() : event.returnvalue = false; if ($('samp').val() != 50) { $('vehicleregfrm').submit(); } else { alert("your message"); } });
try this
$("#vehicleregfrm").submit(function(){ if ($('#samp').val() != 50) { alert('form not sent') homecoming false; } else { alert('form sent') homecoming true; } })
if user write 50 form sent if user write different value nil sent
jquery forms events submit preventdefault
Comments
Post a Comment