Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-28-2013, 12:00 PM   PM User | #1
sami.abid
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
sami.abid is an unknown quantity at this point
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:

Quote:
<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>
sami.abid is offline   Reply With Quote
Old 01-28-2013, 05:33 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,550
Thanks: 9
Thanked 479 Times in 462 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
you just need a form tag.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:15.2% IE7:0.5% IE8:8.4% IE9:8.5% IE10:8.5%
rnd me is offline   Reply With Quote
Old 01-29-2013, 05:33 AM   PM User | #3
sami.abid
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
sami.abid is an unknown quantity at this point
Quote:
Originally Posted by rnd me View Post
you just need a form tag.
Any suggestions on how can that be done ?
sami.abid is offline   Reply With Quote
Old 01-29-2013, 07:22 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,098
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is online now   Reply With Quote
Users who have thanked Philip M for this post:
sami.abid (01-29-2013)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:18 AM.


Advertisement
Log in to turn off these ads.