Pressing enter to submit a form when the submit button is not visible is functional in Firefox, but has no effect in Chrome

There is a form with various input fields and a hidden submit button (hidden using style="display:none").

Interestingly, in Firefox, pressing the return key while an input field is focused automatically submits the form.

However, in Chrome, hitting return does not trigger any action. Is there a way to reintroduce this functionality in Chrome?

If you'd like to test this out yourself, check out the form in Chrome here: http://jsfiddle.net/B59rV/2/

<form method="post" action="/xxxx" accept-charset="UTF-8">

    <input type="hidden" value="SSjovFqEfRwz2vYDIsB6JRdtLAuXGmnT+tkyZnrtqEE=" name="authenticity_token">

    <div class="input text_field">
    <label>Email</label>
    <input type="text" size="30" name="user_session[email]" />
  </div>

  <div class="input text_field">
    <label>Password</label>
    <input type="password" size="30" name="user_session[password]" />
  </div>


    <input type="submit" value="Sign In" style="display: none;" >

</form>

Answer №1

I can't figure out why it's not functioning properly in Chrome. It seems like there might be a bug causing the issue.

But somehow, it's related to that display: none property.

I came up with a messy workaround:

input[type="submit"] {
    position: absolute;
    top: -1000px
}

Instead of hiding it, I moved it off the visible screen.

See Demo Here - works fine in Chrome.

Answer №2

After conducting tests on Chrome 22 and Firefox 18, it seems like this workaround may be the most effective solution

.hide-submit {
    position: absolute;
    visibility: hidden;
}

<button type="submit" class="hide-submit">Ok</button>

Alternatively, a more versatile approach could be used

input[type=submit].hide,
button[type=submit].hide {
    display: block;
    position: absolute;
    visibility: hidden;
}

<input type="submit" class="hide">Go</input>

This method essentially conceals the element in plain sight without the need to push it off-screen

Answer №3

The most effective approach is outlined below:

<input type="submit" hidden />

For instance:

<form onSubmit="event.preventDefault(); alert('logging in!')">
  <label for="email">email:</label>
  <input type="email" name="email" required />

  <label for="password">password:</label>
  <input type="password" name="password" required />

  <input type="submit" hidden />

  <p>Press enter to log in</p>
</form>

Answer №4

It seems like a built-in security measure, although no definitive explanation has been found yet. I conducted a test using http://jsfiddle.net/B59rV/2/ without the password field and the alert popped up as expected. This behavior was also observed in IE8. These are the only browsers currently available on my machine, so I haven't tested it on any others.

Answer №5

In my search for a solution, I stumbled upon a quirky workaround that involves setting the width and height properties to 0. Surprisingly, Chrome doesn't treat this as hiding the element entirely.

Answer №6

Similar to Pioul's response, I found it necessary to implement the following adjustments for an element with input[type=file]:

position:absolute; //using this property ensures that the "hidden" element does not disrupt the layout
width:0;
height:0;
// In versions up to IE7, a small portion of the form element remains visible
// to hide it, utilize opacity=0; The tested element was input:file.
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);

This method has NOT been tested with input[type=text].

While just an alternative approach, I do not believe it offers significant advantages over the approved solution.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for activating and deactivating the scroll trigger within Material UI's useScrollTrigger module?

I'm currently working on setting up a survey page with Material UI in React. My goal is to have the survey questions appear when the user scrolls over them and disappear when they scroll out of view, similar to the behavior on this page. After some r ...

Storing JavaScript variables in a database: A step-by-step guide

For the past few days, I've been working with CakePHP and trying to save a javascript variable into a MySQL database using AJAX (jQuery). Here's the code I've been using: <!-- document javascripts --> <script type="text/javas ...

Error when using the array.filter() method with polygons

I am working with an array named coordinate that contains latitude and longitude values for a polygon. I am trying to find the maximum and minimum latitude/longitude stored in this array. My approach involves using the array.filter() method to filter the ...

Obtain the URL value using jQuery and place it inside a <span> element

How can I insert a href value into the span tag like this? <p class="name"> <a download="adja-lo.pdf" title="adja-lo.pdf" href="http://localhost/MatrixDRSnews/apps/Matrix/server/php/files/adja-lo.pdf">adja-lo.pdf</a> </p> ...

Guide to redirecting on click when utilizing an iframe

I needed to prevent the page from reloading before the action was complete by using an iframe. However, I encountered an issue where I needed the page to refresh after the action took place. I attempted two methods to achieve this - refreshing the page and ...

Creating a polished and stylish centered responsive image with Bootstrap 3

I am facing an issue with centering a styled responsive image on my website. Upon debugging, I discovered that the class "portimage" is causing the responsiveness to break. My requirement is to ensure that the images do not exceed 700px in size and have a ...

spinning camera around a globe with javascript and three.js

In my project, I am working on enabling a player to navigate in a first-person view on a planet using three.js and JavaScript. There are two key aspects I am focusing on: a) Implementing player movement around the planet, which involves two types of movem ...

Issue with Vuex not functioning properly in Nuxt.js

I'm facing an issue with setting the state in Vuex on my Nuxt.js App. It seems to not be working correctly. So, here is how I am trying to set the state using the fetch method: fetch({app, store, route}) { app.$axios.$get(`apps/${route.params ...

Recovering antiquated submission script in JavaScript

Here is a form with input data: <form id = 'myform'> ... <td><input type="checkbox" name="supplier_aid" value="on" checked disabled >{$output.t_artikelnr}</td> <td><input type="checkbox" n ...

How can I transform this in JavaScript so that it returns a Promise?

Currently, I am trying to implement code that I found in a SaaS's example. The goal is to retrieve the correct URL for a specific action. The sample code provided by the SaaS looks like this, but I would like to modify it so that it returns a Promise ...

What is the best way to show a loading spinner as my Next image component loads, especially when there is an existing image already being displayed?

I'm trying to incorporate a loading spinner or any other HTML element while an image is being loaded. Currently, I am utilizing the ImageComponent to showcase images in a random movie generator. Although I managed to make the spinner work for the init ...

Sending a large number of values unrestrictedly via ajax

I'm currently working on implementing a filter for the Google Maps API on our website. This filter will allow users to display information related to specific locations that they select by checking corresponding checkboxes. As I am still relatively ne ...

Tips for accessing every "results" (parameters) from an API

Here is the response I received after making an API call in my attempt to retrieve each "bloc" result using a .forEach. const app = express(); const axios = require('axios') jobList = []; app.get('/getAPIResponse', function(req, res) ...

How can you assign a default value in a React select dropdown and dynamically add the remaining values?

I'm currently developing a React application that includes a form with a select dropdown feature. My goal is to have the 'uom' field value from the selected product record automatically set as the default option in the dropdown when the user ...

Tap the mobile menu button twice to toggle the menu

Incorporating: Visual Studio 2013, ASP.NET (VB) Webforms. Upgrading an existing WebForms website from .NET 2.0 to .NET 4.5 and implementing mobile-friendly features for better Google support. I have added a button to the top right corner as follows: < ...

Should we consider the implementation of private methods in Javascript to be beneficial?

During a conversation with another developer, the topic of hacking into JavaScript private functions arose and whether it is a viable option. Two alternatives were discussed: Using a constructor and prototype containing all functions, where non-API meth ...

Tips on inserting text into form input fields

I need some guidance on how to enhance my form input functionality. The form currently consists of an input box and a submit button. When the user clicks submit, the form content is submitted and processed using javascript. What I am aiming for is to autom ...

Is there a way to properly access and interpret a .log extension file within a React component?

import React from "react"; import "./App.css"; function FileReaderComponent() { const readLogFile = () => { if (window.File && window.FileReader && window.FileList && window.Blob) { const preview = document.getElementByI ...

Triggering a Bootstrap 5 dropdown through code is only effective within the browser's developer console, rather than standard JavaScript implementation

I attempted to display a Bootstrap5 dropdown by clicking on a link in my web application. Despite trying various methods, such as dispatching events and utilizing the bootstrap Dropdown classes, I was unable to achieve success. Interestingly, both approach ...

Searching in real-time with ajax in CodeIgniter framework is a seamless and efficient process

I'm a beginner in CodeIgniter and eager to learn. Currently, I'm facing an issue where the data is not being populated on the search page. In the model: function fetch_data($query) { $this->db->select('*'); $this-> ...