Reply
onkeypress
Old 03-23-2005, 04:00 PM onkeypress
dan245's Avatar
Skilled Talker

Posts: 59
Location: Massachusetts, USA
here is my code! I want it to display that text, but it won't work. Help would be nice...

Code:
if ( event.keyCode == 32 ) { alert ('you pressed space!'); }
dan245 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 03-23-2005, 04:17 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Encoding Numbers as Base 36
Posts: 3,108
Location: Toronto, Ontario
I think you'll need to attach the code to an event. For example, in the following I attached a function to the onkeydown event:

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript">
        document.onkeydown = docKeyDown;

        function docKeyDown(e)
        {
            if(!e) e = window.event;

            if(e.keyCode == 32)
                alert("Pressed space!!!");
        }
    </script>
</head>
<body>

Blah blah blah

</body>
</html>
__________________
Devlog - Latest PHP Article: MVC with the Zend Framework
::The New Tech - Technology Forum
Christopher is offline
Reply With Quote
View Public Profile Visit Christopher's homepage!
 
Old 03-23-2005, 04:34 PM
dan245's Avatar
Skilled Talker

Posts: 59
Location: Massachusetts, USA
It didn't work, I put the onkeypress="docKeyDown()" in the text area.
dan245 is offline
Reply With Quote
View Public Profile
 
Old 03-23-2005, 08:52 PM
dk01's Avatar
Ultra Talker

Posts: 373
Location: Ames, IA
try removing the ().

-dk
__________________
Did I help you? If so, be nice and throw me some TP
dk01 is offline
Reply With Quote
View Public Profile Visit dk01's homepage!
 
Reply     « Reply to onkeypress
 

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11578 seconds with 13 queries