Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Script not recognizing the "Enter" keypress via keyboard

    Hi there,

    I am building a search box to use on our library website, I am very new to programming languages. I have made a small JavaScript and it has come out well as I am able to enter the search term and it redirects to an external website. However the search button is only working when I click on "search". When I press the enter button via keyboard after typing the search it doesn't recognize the keypress even though the script is meant to recognize the key press. Was wondering if you guys can help me please.

    here's the script:

    <p><a id="logo" href="/"><img style="width: 137px; height: 24px;" title="SpringerLink" alt="Logo Springer" src="http://link.springer.com/static/0.6043/sites/link/images/logo.png" width="158" height="30" /></a></p>
    <script type="text/javascript">// <![CDATA[

    function econlitSearchGo(){
    var url="http://link.springer.com/search?query=";
    var url2=""
    var searchInputeconlit = document.getElementById("econlitSearchInput");
    window.open(url + encodeURIComponent(searchInputeconlit.value) + url2);
    }
    // ]]></script>
    <div>
    <div style="position: absolute; left: -1000em; width: 20em;" id="enterText">Enter your search terms:</div>
    <input id="econlitSearchInput" onkeypress="handleKeyPress(event,this.form)" size="30" type="text" /><input onclick="econlitSearchGo()"value="Search" type="button" /></div>

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,333
    Thanks
    11
    Thanked 587 Times in 568 Posts
    you just need a form tag.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #3
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rnd me View Post
    you just need a form tag.
    Any suggestions on how can that be done ?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by sami.abid View Post
    Any suggestions on how can that be done ?
    Code:
    <form id = "myform>
    <div>
    <div style="position: absolute; left: -1000em; width: 20em;" id="enterText">Enter your search terms:</div>
    <input id="econlitSearchInput" onkeypress="handleKeyPress(event,this.form)" size="30" type="text" />
    <input onclick="econlitSearchGo()"value="Search" type="button" /></div>
    </form>

    Solomon, one of David's sons, had 300 wives and 700 porcupines.
    - Pupil's answer to Catholic Elementary School test.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    sami.abid (01-29-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •