I have a problem with my script. It is only partly working. If i enter less then 15 charachters the alert appears but then i click ok on the alert massage and the from gets send anyway. I am not sure waht i'm doing wrong. Here is my script:
function checktextarea() {
var minLength = 15;
var $textarea = $('#massage');
if($textarea.text().split(/\s+/).length < minLength) {
alert('You need to enter at least ' + minLength + ' words');
return false;
}
}
This is the html:
<form action="kontaktsi.php" name="myForm" id="myForm" method="post" class="contact_form" onsubmit="checktextarea()">
<span class="sporo">
<input type="text" id="fname" name="fname" class="contacttextform form-control" placeholder="Name" required>
</span>
<input type="email" id="email" name="email" class="contacttextform" placeholder="Your email" required><br><br>
<textarea name="message" id="message" cols="8" rows="8" class="contacttextarea" placeholder="text text text?" required></textarea>
<br>
<div class="send">
<input name="send" type="submit" class="contactformbutton" style="width:150px;" value="Send">
</div>
</form>