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 7950459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:16:44+00:00 2026-06-04T02:16:44+00:00

If an HTML form field has focus and you hit enter, the form will

  • 0

If an HTML form field has focus and you hit enter, the form will be submitted (unless you’ve done fancy things to bypass that). Weirdly though, if JavaScript adds a field into the form, that enter-to-submit behavior appears to break. For example:

http://jsfiddle.net/SChas/1/

function goose() { 
  document.getElementById("addhere").innerHTML="<input name=goose value=honk>";
}

function checkForm() {
  alert("ok");
}​

--

<form onsubmit="checkForm();">
  <input name="duck" value="quack">
  <div id="addhere"></div>
  </form>
<button onclick="goose();">add a goose</button>

​
(This is a contrived example attempting to be as concise as possible. The original code involved is more modern code with events attached in JavaScript, etc. But this is the simplest code that replicates the issue. Also, it is necessary in the real use case to dynamically modify the form by adding/removing fields.)

Anyway, you’ll get a form that has a single field with a value “duck”. Click into it and hit enter, and the form will submit (you’ll see an “ok” alert and then JSFiddle will tell you not to post!).

However, if you click “add a goose”, you get a new field. And now, you cannot hit enter to submit the form.

Why is this happening? I can’t find anything about this behavior via google, perhaps I’m using the wrong search terms. But it happens in IE on Windows and Chrome and FF on OSX at least. So it seems like an intentional, perhaps to-specification, behavior. Is it some kind of security protection?

And, is there any way to restore the enter-to-submit behavior on the form once a field is inserted? A way other than to add onkey* events to the input fields?

FWIW, it doesn’t seem to matter if the inputs are added via DOM methods (appendChild), or setting the innerHTML, using jQuery or old fashioned JavaScript.

  • 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-06-04T02:16:46+00:00Added an answer on June 4, 2026 at 2:16 am

    This is because the enter-to-submit behaviour only happens when it’s the only input on the form.

    You can restore it by putting a input with type=submit on the form, it doesn’t even have to be visible.

    Check it out: http://jsfiddle.net/SChas/10/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an input field on my plain html form that I would like
I have an HTML form which has a field with an ID of 'soln_c_links'
User has html-form, then user fills all field and data transferred to PHP script.
A form on my website's contact -us HTML page has two fields 1) subject
HTML has an input button type to reset all fields in a form to
hi i have a sign up form , it has six input fields html
I am trying to copy a name of the selected html form option field
So I'm using this HTML form for a simple search field <form action =
ASP.NET MVC seems to correctly automatically bind between HTML form's file input field and
We have got an extjs 3.1.1 form with file upload field ( http://www.extjs.com/deploy/dev/examples/form/file-upload.html from

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.