Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keyboard event

Status
Not open for further replies.

djack2

Programmer
Dec 12, 2000
16
0
0
US
I need to have a piece of coldfusion code ran, when a certain "F" key is pressed. For example, when "F2" is pressed some code would be run. Like printing a statement to the screen. Can this be done in javascript? If not, can it be done at all?
 
Hi djack2,

The difficulty is that CF is a server script. So, if the client does an action, the page should be resent to the CFserver to be processed. The following demonstrates this:
(had to use 'f' because F2 is a system key, which cannot be used)

<SCRIPT TYPE=&quot;text/javascript&quot;>
<!--
function getkey(e)
{
if (window.event) { key = window.event.keyCode }
else if (e)
key = e.which
else
key = null;
if (key == '102') {
window.location.href=&quot;somePage.cfm?keyPressed=&quot;+key
}
}
//-->
</SCRIPT>

<BODY onkeypress=&quot;return getkey(event)&quot;>

Then you should use a CF code like the following:

<cfif IsDefined(&quot;url.keyPressed&quot;)>
<cfif url.keyPressed is &quot;102&quot;>
Code to be executed
</cfif>
</cfif>

Alas, as i said above, you cannot use system keys like F2, so i'm affraid it will not fully serve your needs. Maybe you can use Return(code 13) or space (code 32) instead?

Hope you get any further anyhow? :p

Kristof
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top