using the key handling function

P

Paul Kirk

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?
--
 
K

kaeli

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
-------------------------------------------------
 
L

Lasse Reichstein Nielsen

Paul Kirk said:
<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
 
P

Paul Kirk

Thank you that worked a treat.
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
/ / (e-mail address removed) Weybridge Surrey KT13 0RH
\_\/\ (e-mail address removed) http://support.xilinx.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top