How to enable enter button android mobile browser in keyboard?

76 Points
33 Posts

I'm input field to enter comment. I has keyDown JavaScript event.

<div class="Comment">Add Comment
      <input onkeydown="javascript:AddComment(event,this,<%=Answer.ID %>)" class="PostInput" type="text" />

Its working in Desktop web browser but not working in mobile web browser.

In mobile web browser, showing Next button instead of submit button in virtual keyboard. And causing issue.


Views: 197
Total Answered: 2
Total Marked As Answer: 0
Posted On: 08-Apr-2023 00:15

Share:   fb twitter linkedin
Decorate input with form tag. I will enable the enter button.
 - Brian  08-Apr-2023 07:28
264 Points
57 Posts

Try to put form tag as:

<div class="Comment">Add Comment
      <form action="javascript:;"><input onkeydown="javascript:AddComment(event,this,<%=Answer.ID %>)" class="PostInput" type="text" /></form>
Posted On: 10-Apr-2023 05:01
Thanks. Works for me.
 - Stevan  19-Apr-2023 03:24
84 Points
27 Posts

f you want to enable the Enter key on the keyboard to submit a form in a mobile browser using HTML and JavaScript, you can add the following code to your HTML file:

<form onsubmit="return false;">
  <input type="text" name="input_field" />
  <button type="submit" onclick="submitForm()">Submit</button>

  function submitForm() {
    // Do whatever you need to do with the form data here.
    // Then reset the form and focus the input field again.

  document.querySelector('input[name="input_field"]').addEventListener('keyup', function(event) {
    if (event.keyCode === 13) {

In this example, we have added an event listener to the input field that listens for the Enter key to be pressed (key code 13). When the Enter key is pressed, the submitForm() function is called, which will handle the form submission. We have also added a "Submit" button that calls the same function when clicked.

Note that we have included event.preventDefault() in the keyup event listener to prevent the default behavior of the Enter key (which is to add a new line in the input field).

Posted On: 24-Apr-2023 23:54
 Log In to Chat