Gossamer Forum
Home : General : Internet Technologies :

Javascript Question - onclick alternative

Quote Reply
Javascript Question - onclick alternative
I have a small piece of JS on a page. It includes a function called startSearch. Typical form with a field and an input button. The input in the form however does not call a script, it calls this JS function on the page. I'm using the input line below:

Code:
<input" type="Button" value=Go onclick="startSearch()">

With this when I enter a value in the field and click on the "Go" button all works well. However, when I enter a keyword to search and hit the "Enter" key (not click a button) it does nothing.

How can I modify this input statement to catch both the button click and a hit of the enter key?

As you can guess I know nothing about JS. Hope this makes sense! Crazy

Safe swoops
Sangiro
Quote Reply
Re: [sangiro] Javascript Question - onclick alternative In reply to
See http://www.webreference.com/...dhtml/chap8/2/2.html
as one example to capture the enter or return key
at "Submitting a Form by an Enter Key Press in Any Text Box "

The enter key creates an event and you have to have code to capture this event
and do something or nothing.

You may have to search some more for a cross browser version if this does not do the trick.

See also http://www.dansteinman.com/...o/en/keystrokes.html for NS vs IE differences
and look and see if this will work on Unix or Linux Browsers [ probably not ].


Hope this helps cornball
Quote Reply
Re: [sangiro] Javascript Question - onclick alternative In reply to
If it's a form on its own, then you can make it an onsubmit instead. You may also have to return false; if you don't actually want to form to submit and make a request.

Adrian
Quote Reply
Re: [brewt] Javascript Question - onclick alternative In reply to
Thanks guys!

I haven't tried the "onsubmit" but have found a nice small little perl/cgi script that will do the same as this JavaScript. May just go with that to get around those people who have JS disabled as well.

Safe swoops
Sangiro