Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6338421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:26:28+00:00 2026-05-24T19:26:28+00:00

I want to submit the form by press the ENTER key. But it also

  • 0

I want to submit the form by press the ENTER key.
But it also change the line in content.
How to prevent this?

This is my code, but when hit ENTER, the … run and Cursor moved to the next line:

function postmessage(e) {
    if(e) {
        e.preventDefault = null || e.preventDefault;
        if(e.preventDefault) {
            e.preventDefault();
        } else {
            e.returnValue = false;
        }
    }
    ....
    return false;
}

function submitmessage(e) {
    if(e.keyCode == 13) {
        postmessage(e);
    }
    return false;
}

function bindEvent(el, eventName, eventHandler) {
  if (el.addEventListener){
    el.addEventListener(eventName, eventHandler, false); 
  } else if (el.attachEvent){
    el.attachEvent('on'+eventName, eventHandler);
  }
}

bindEvent(text, 'keydown', submitmessage);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:26:29+00:00Added an answer on May 24, 2026 at 7:26 pm

    While I completely agree with @Peter in that this will create a very awkward and annoying user experience, here’s how to achieve it code-wise: Capture the event on a keydown, and bypass the newline with event.preventDefault(). Then manually submit your form.

    Something like this:

    var el = document.getElementById('#my_textarea');
    if (el.addEventListener)
    {
        el.addEventListener('keydown', checkEnter(event), false); 
    } 
    else if (el.attachEvent){
        el.attachEvent('keywodn', checkEnter(event));
    }
    
    function checkEnter(event)
    {
        var charCode = (event.which) ? event.which : event.keyCode
    
        // Enter key
        if(charCode == 13) {
            event.preventDefault();
            document.myform.submit();
            return false;
        }
    }
    

    MDN Docs:

    • https://developer.mozilla.org/en/DOM/event.preventDefault
    • https://developer.mozilla.org/en/DOM/element.addEventListener
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to submit a form like this: <input type=button onclick=$('#form1').submit(); value=Create /> but
Let's say I'm at http://www.domain.com/page.html . I want to submit this form: <FORM METHOD=post
I want to retain the conventional 'form submits when i press Enter' behavior because
i have a form with some textbox When a user press the enter key
$('#search_form').submit(function(e) { //e.preventDefault(); return false; }) This works just fine to prevent form submission
I want to send a user feedback form through email. when they press submit
I want to create a search form. When I enter my query and press
I want to submit a form that have many checkboxes with different values, using
I want to submit a form without page refresh using jQuery. I found some
I have a case where i want to submit a form and get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.