Friday, November 16, 2012

php – Submit textarea form without a submit button with Enter key press

Background:

I\’m making a facebook wall-alike page, which will have many posts and you should be able to comment every post. So in this one page there are many forms (of course). And I only need to submit one of them.


So yes, I have found answers to this question , but none of them work, so asking here:


I got a form like this:



<form enctype=\"text/plain\" action=\"submitcomment.php\" method=\"post\" target=\"output_frame\" id=\"comment<?php echo $prepare_data[\'post_id\']; ?>\">
<textarea name=\"comment\" id=\"comment\" onkeypress=\"return submitViaEnter(event)\" value=\"\" autocomplete=\"off\"></textarea>
<input type=\"hidden\" name=\"hiddenid\" id=\"hiddenid\" value=\"<?php echo $prepare_data[\'post_id\']; ?>\" />
</form>


and my JavaScript function looks like this:



function submitViaEnter(evt) {
evt = (evt) ? evt : event;
var target = (evt.target) ? evt.target : evt.srcElement;
var form = target.form;
var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
if (charCode == 13) {
document.forms[this.form.id].submit();
alert(\"sent!\");
return false;
}
return true;
}


If I use a textbox, it works, but when I use textarea, it is not working. Trying to press enter does nothing.






Rating: 3 out of 5 based on 3 ratings



The post php – Submit textarea form without a submit button with Enter key press appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/php-submit-textarea-form-without-a-submit-button-with-enter-key-press.html

No comments:

Post a Comment