I want when my input field of a form is empty it shows me alert and stops form submission. Now problem with my code is that it only shows alert but does not stop form submission . Here my html input field and script:
function required() {
var empt = document.forms["me_validate"]["insert_vender_emails"].value;
if (empt == "") {
alert("Please fill out the vendor email field");
}
}
<form enctype="multipart/form-data" id="validate-me" method="post" class="form-horizontal" action="phpcode_class.php" role="form" name="me_validate" onsubmit="return required()">
<textarea type="text" id="tags" name="insert_vender_emails" class="form-control" placeholder="">
<?php if($n_vendors!='' ) { echo $n_vendors; } else { echo $rfq[ 'vender_emails']; } ?>
</textarea>
</form>
I really got stuck in this. Please help me to get rid out of this...thanks in advance