سؤال

Send with button works, but press enter he make a new row. I need to send with enter. Any suggestion? :)

 echo "</div>\n";
 echo "<div style='float: right; width: 10%;'>";
 echo "<input type='submit' name='send' id='send' value='&nbsp;' onclick="$('#loading').fadeIn(); sAjaxObj = 'profile-msgs'; sAjaxUrl = ''; \$.post('/ajax.php?act=message_save&ts=' + Number(new Date()), \$('#form-message').serializeArray(), fnAjaxEvaluateReload);" class='button-ok' />&nbsp;";

 echo "</div>\n";
 echo "<div style='clear: both;'></div>\n";
 echo "</form>\n";
 }
 }

Thnaks guys

هل كانت مفيدة؟

المحلول

Try adding this between your existing script tags:

<script>
$(document).ready(function() {
    $('#form_message').keyup(function(e) {
        var keycode = (e.keyCode ? e.keyCode : e.which);
        if(keycode == '13'){
            $('#send').click();
        }
    });
});
</script>

Note that this is jQuery code and you will need to have the jQuery library loaded -- but your existing code is also jQuery, so you probably have done that already.

نصائح أخرى

To send on "enter" you would need to not allow the creation of new lines in the textarea (as you cannot know whether the user wants a new line or to submit when they press enter, computers aren't psychic).

If you need new lines in the textarea, then you cannot do "submit on enter".

If you do not need new lines, then change it to a <input type="text" />

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top