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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:35:51+00:00 2026-05-12T23:35:51+00:00

I have a textbox and whenever the user presses a key it’s checked to

  • 0

I have a textbox and whenever the user presses a key it’s checked to see if the user pressed enter. If the enter key is pressed, i want to add all the info in the textbox and transfer the user to a different url.

<script language="javascript" type="text/javascript">
    function checkEnter(e){ //e is event object passed from function invocation
        var characterCode;

        if(e && e.which){ //if which property of event object is supported (NN4)
            e = e;
            characterCode = e.which; //character code is contained in NN4's which property
        }
        else{
            e = event;
            characterCode = e.keyCode; //character code is contained in IE's keyCode property
        }

        if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
            var searchLink = '/Search/?Keywords=' + document.getElementById('<%= searchBox.ClientID %>').value;

            transferUser(searchLink);         
            return false; 
        }
        else{
            return true; 
        }
    }

    function transferUser(url) {
        window.location.href = url;
        window.location.replace(url);   
    }
    </script>

Search: <input name="ctl00$searchBox" type="text" id="ctl00_searchBox" class="header_line_search_box_textbox" onKeyPress="checkEnter(event);" />

I have tried every possible combination, but nothing happens. The site just refreshes itself.

I also need somehow to convert the text from the user to html safe, must like the HttpUtility.EncodeUrl in aspx.

  • 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-12T23:35:52+00:00Added an answer on May 12, 2026 at 11:35 pm

    I’m not sure you need all of this. Normal, built-in behavior for the following HTML markup does exactly as you want without the need for any JavaScript:

    <form method="get" action="/Search/">
        <input type="text" name="Keywords">
    </form>
    

    However, it is important that your UI have some sort of way to submit the form that doesn’t involve a key stroke. This is for two reasons:

    1. As Jorn pointed out, it might not be readily apparent that the key submits the form.
    2. Having no submit button may break usability for users who use alternative input devices.

    Because of the above reasons, the following is suggested:

    <form method="get" action="/Search/">
        <input type="text" name="Keywords">
        <input type="submit" value="Search or 'go' or whatever">
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textbox and want an event triggered whenever it is updated, whether
I have a textbox with an 'Add to clipboard' button next to it. Whenever
I have a textbox, and whenever the value of the box changes, I want
I have a search text box on my WPF Windows. Whenever, the user presses
What's the simplest way to have a function called whenever the user hits enter
Im creating forum like application and I have textbox where users can enter tags
Desktop window application. I have textbox in which user give values in numbers. what
I have a textbox and a label. If the user wants to change the
I want to display a note to the user whenever the focus comes to
I have a table with some rows and inputs inside them. I want add

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.