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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:50:47+00:00 2026-06-08T00:50:47+00:00

Possible Duplicate: Stop Enter/Return key submitting a form I am trying to create a

  • 0

Possible Duplicate:
Stop Enter/Return key submitting a form

I am trying to create a simple search form using css I found online. I want users to be able to hit the ENTER key from within a textbox and have it run a query without having the user to click on the button. I tried checking for the ENTER key on keydown, but the page keeps refreshing for some reason. What is the cause of this refresh?

.searchform {
    display: inline-block;
    zoom: 1; /* ie7 hack for display:inline-block */
    *display: inline;
    border: solid 1px #d2d2d2;
    padding: 3px 5px;

    -webkit-border-radius: 2em;
    -moz-border-radius: 2em;
    border-radius: 2em;

    -webkit-box-shadow: 0 1px 0px rgba(0,0,0,.1);
    -moz-box-shadow: 0 1px 0px rgba(0,0,0,.1);
    box-shadow: 0 1px 0px rgba(0,0,0,.1);

    background: #f1f1f1;
    background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ededed));
    background: -moz-linear-gradient(top,  #fff,  #ededed);
    filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed'); /* ie7 */
    -ms-filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed'); /* ie8 */
}
.searchform input {
    font: normal 12px/100% Arial, Helvetica, sans-serif;
}
.searchform .searchfield {
    background: #fff;
    padding: 6px 6px 6px 8px;
    width: 202px;
    border: solid 1px #bcbbbb;
    outline: none;

    -webkit-border-radius: 2em;
    -moz-border-radius: 2em;
    border-radius: 2em;

    -moz-box-shadow: inset 0 1px 2px rgba(0,0,0,.2);
    -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,.2);
    box-shadow: inset 0 1px 2px rgba(0,0,0,.2);
}
.searchform .searchbutton {
    color: #fff;
    border: solid 1px #494949;
    font-size: 11px;
    height: 27px;
    width: 35px;
    text-shadow: 0 1px 1px rgba(0,0,0,.6);

    -webkit-border-radius: 2em;
    -moz-border-radius: 2em;
    border-radius: 2em;

    background: #5f5f5f;
    background: -webkit-gradient(linear, left top, left bottom, from(#9e9e9e), to(#454545));
    background: -moz-linear-gradient(top,  #9e9e9e,  #454545);
    filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#9e9e9e', endColorstr='#454545'); /* ie7 */
    -ms-filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#9e9e9e', endColorstr='#454545'); /* ie8 */
}

#search {margin-top:30px; marin-right:auto;}

With the following form:

<div align="center" id="search">
    <form class="searchform">
        <input class="searchfield" style="color:#636363" type="text" value="Title/Album..." onkeydown="if (event.keyCode == 13) {querySong();}" onfocus="if (this.value == 'Title/Album...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Title/Album...';}" />
    </form>
    <form class="searchform">
        <input class="searchfield" style="color:#636363" type="text" value="Artist..." onkeydown="if (event.keyCode == 13) {querySong();}" onfocus="if (this.value == 'Artist...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Artist...';}" />
        <input class="searchbutton" type="button" value="Song" onclick="querySong()"/>&nbsp
        <input class="searchbutton" type="button" value="Album" onclick="queryAlbum()"/>
    </form>
</div>
  • 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-08T00:50:48+00:00Added an answer on June 8, 2026 at 12:50 am

    You need to prevent the form from performing the default action on Enter which is to submit the form.

    This is a bit heavy handed, you’ll want to select the appropriate form for your case, but basically you just need to return false to prevent the default behavior.

    $('form').submit( function() { return false; } );
    

    Or without jQuery

    var el = document.getElementById('formId');
    
    if (el.addEventListener) {
      el.addEventListener('submit', preventDefaultAction, false); 
    } else if (el.attachEvent)  {
      el.attachEvent('submit', preventDefaultAction);
    }
    
    var preventDefaultAction = function () { return false; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to stop C++ console application from exiting immediately? I am trying
Possible Duplicate: Detecting moved files using FileSystemWatcher I'm trying to monitor moved files with
Possible Duplicate: Best way to stop SQL Injection in PHP I'd like a simple
Possible Duplicate: Stop chrome from auto styling input type=search I want to add that
Possible Duplicate: NSTimer doesn't stop I am using [NSThread exit] to leave the NSTimer
Possible Duplicate: NSTimer doesn't stop I am using a NSTimer to update the value
Possible Duplicate: Rails console, how to stop output of return value? Consider this session
Possible Duplicate: Why does overflow hidden stop floating elements escaping their container? Why my
Possible Duplicate: Best way to stop SQL Injection in PHP I am creating a
Possible Duplicate: Best way to stop SQL Injection in PHP I have seen some

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.