I am having an issue with the textbox keypress function. If the textbox field is empty, I do not want to post any values.
My current functions are working fine. When the textbox field is empty and I press enter key, it goes to the next line as expected. However, if I press the enter key two times, the values are posted.
Can someone please help me identify the problem in my code?
$(".ppop-comment").keypress(function(e) {
if($('#add_comment').val()=="") {
if (e.which == 32)
return false;
} else if (e.keyCode == 13 && !e.shiftKey && !$('#add_comment').val()==" ") {
$("#submit-comment").click();
}
});
<form id="commentform" method="post">
<textarea id="add_comment" name="meetnewpeople[message]" class="popup-comment"></textarea>
<input id="submit-comment" type="button" value="Post a comment" />
</form>