Streaming live at 10am (PST)

Is it possible to press "Enter" on the keyboard to trigger the search button?

I would like to remove the search button and is it possible to submit the search input by pressing “Enter” on the keyboard? Does Webflow supports this natively or it requires custom code?

What search button do you mean? Do you have a share link?

If I can take a look at your project, I can help you better.

You could trigger it with Javascript.

$(function() {
  $('inputfield').on('keypress', function(e){
    if(e.keyCode == '13'){
      // enter pressed
      e.preventDefault();
      $('.search-button').trigger('click'); 
    } 
  });
});
3 Likes

Thanks @ElviraNL for the help!

1 Like

Glad I could help. You’re welcome.

Where do you place this? In the before ? or somewhere else?

@Emmanuel_Kaska In the before indeed.

Thanks for this @ElviraNL. I just needed this but wanted to convert it to vanilla javascript. So in case anyone else wants it:

 document.addEventListener("DOMContentLoaded", function() {
      document.querySelector('input').addEventListener('keypress', function(e){
    if(e.keyCode == '13'){
      e.preventDefault();
      document.querySelector('input[type="submit"]').click(); 
    } 
      });
    });

It seems like Webflow has now added this natively to the Site Search element.

On their support page for this component, it says this:

Submit button (optional): a button to submit the search — which you can hide if you’d like a simple “Enter” to submit the search.

It’s worth noting the “Enter” functionality only works on the live, published staging URL or domain. It doesn’t work in preview mode.

2 Likes