By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

using the key handling function

P: n/a
Hello

I have a piece of simple code which take the user inputs and depending
which check box is selected directs them to a different page.

<form name="allform">
<input type="radio" name="allsearch" value="Weaksearch">
<font face="Arial,Helvetica" >Weak&nbsp;</font><br>
<input type="radio" name="allsearch" value="Pinsersearch">

<font face="Arial,Helvetica" >Pinser&nbsp;</font><br>
<input type="radio" name="allsearch" value="Brutesearch">
<font face="Arial,Helvetica">Brute note&nbsp;</font> <br>
<input type="radio" name="allsearch" checked
value="gogsearch">
<font face="Arial,Helvetica">Google</font> <br>
<input type=text name=allsearchtext size=10 maxlength=255>

<input type="button" onClick="locateall(this)" value="Go"
name="button">
</form>

This works but the user needs to hit the go button, if they just hit
return the text field is emptied, I would like if the user hits ENTER,
the search begins.

I believe I can add something similar as

if (window.event.keyCode == 13)

But I am not sure how to incorporate it in the form?
--

Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Paul Kirk <pa*******@xilinx.com> writes:
<input type="button" onClick="locateall(this)" value="Go"
name="button"> .... This works but the user needs to hit the go button, if they just hit
return the text field is emptied,
What happens is that the form is submitted. The missing (and
required!) action attribute is interpreted as pointing to the page
itself, so the page is reloaded.
I would like if the user hits ENTER, the search begins. I believe I can add something similar as

if (window.event.keyCode == 13)


Overkill.
Just put the call to locateall in the onsubmit handler of the form tag:

<form id="allform" onclick="locateall(this)" action="noJS.html">
(fix the locateall function so it expects the form as argument and not
the button).

Change the <input type="button" ...> to
<input type="submit: value-"Go" name="button">

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
In article <3F***************@xilinx.com>, pa*******@xilinx.com
enlightened us with...
This works but the user needs to hit the go button, if they just hit
return the text field is emptied, I would like if the user hits ENTER,
the search begins.

I believe I can add something similar as

if (window.event.keyCode == 13)

But I am not sure how to incorporate it in the form?

You don't need to - the enter key is submitting the form.
Try this.

<form name="allform" onSubmit="locateall(this);return false;">

Your Go button calls that function onClick - so you may need to play
with the "this" keyword, which refers to the button when the button is
clicked but to the form when the enter key is pressed and the form is
submitted.

--
-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #3

P: n/a
Thank you that worked a treat.

kaeli wrote:
In article <3F***************@xilinx.com>, pa*******@xilinx.com
enlightened us with...
This works but the user needs to hit the go button, if they just hit
return the text field is emptied, I would like if the user hits ENTER,
the search begins.

I believe I can add something similar as

if (window.event.keyCode == 13)

But I am not sure how to incorporate it in the form?


You don't need to - the enter key is submitting the form.
Try this.

<form name="allform" onSubmit="locateall(this);return false;">

Your Go button calls that function onClick - so you may need to play
with the "this" keyword, which refers to the button when the button is
clicked but to the form when the enter key is pressed and the form is
submitted.

--
-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------


--
Regards
Paul Kirk
/ /\/ Paul Kirk Xilinx Inc.
\ \ Customer Apps Engineer 203 Brooklands Road
/ / Pa*******@xilinx.com Weybridge Surrey KT13 0RH
\_\/\ Eu*********@xilinx.com http://support.xilinx.com
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.