Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3624332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:29:40+00:00 2026-05-18T23:29:40+00:00

Here’s the problem, document.onkeydown = checkkeycode I’m passing two variable to checkeycode e which

  • 0

Here’s the problem, document.onkeydown = checkkeycode

I’m passing two variable to checkeycode e which is storing the event and hence keycode and the array circle which I want to update with variable c’s latest position. when I pass circle to the function, it becomes undefined hence
{circle[4] = c._.ty};
returns an undefined error
I tried putting document.write(circle);
into the document and it just wrote undefined and when I switched it with E it became a keyboard object. What I need solved is:

  1. how do I pass the array circle to the function so that when raphael translates the circle, it updates the values in circle?

  2. in the if (keycode == blah ) do I just do {c.translate(value)} {circle[4] = c._.ty} ?
    do I append two different function to a single if event?

<html>  

<head>  

<script language="javascript" type="text/javascript" src="/home/andrew/Documents/rahpael/raphael-min.js"></script>

</head>

<body>

<script language="javascript">

var paper = Raphael(50, 50, 420, 300);
var d = paper.rect(150, 150, 30, 30);
var c = paper.circle(50, 50, 40);
var circle = [c.attrs.cy, c.attrs.cx, c.attrs.r, c._.tx, c._.ty];
var rectie = [ d.attrs.x, d.attrs.y, d.attrs.height, d.attrs.width];

document.onkeydown = checkKeycode

function checkKeycode(e, circle) {
var keycode;
if (window.event) keycode = window.event.keyCode;  
else if (e) keycode = e.which;  
if (keycode == 40) { c.translate(0, 10)}; //{circle[4] = c._.ty};// down  
if (keycode == 39) { c.translate(10, 0)}; // right  
if (keycode == 38) { c.translate(0, -10)}; // up  
if (keycode == 37) { c.translate(-10, 0)}; // left  

}  
 // deleted some comments I've made so far.  

</script>  

</body>  
</html>  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:29:41+00:00Added an answer on May 18, 2026 at 11:29 pm

    A couple of issues there:

    1) Passing arguments

    I’m passing two variable to checkeycode

    No, you aren’t. The browser will pass one argument to it, the event (unless it’s IE, but you’ve handled that).

    If you change:

    document.onkeydown = checkKeycode
    

    to

    document.onkeydown = function(e) {
        checkKeycode(e, circle);
    };
    

    …you’ll be passing in the circle you defined at global scope.

    2) Names

    Your checkkeycode function accepts the arguments e and circle, but appears to use e and c instead.

    (Your checkkeycode code already closes over the circle at global scope anyway, so you could just drop the circle argument from the definition of checkkeycode and use circle rather than c. But best to keep things modular if you can, by passing the argument into the function.)

    So if you’re going modular and just closing over circle in the event handler:

    var paper = Raphael(50, 50, 420, 300);
    var d = paper.rect(150, 150, 30, 30);
    var c = paper.circle(50, 50, 40);
    var circle = [c.attrs.cy, c.attrs.cx, c.attrs.r, c._.tx, c._.ty];
    var rectie = [ d.attrs.x, d.attrs.y, d.attrs.height, d.attrs.width];
    
    
    document.onkeydown = function(e) {
        return checkKeycode(e, circle); // Event handler is closure over `circle`
    };
    
    //                       v-- `c`, not `circle`
    function checkKeycode(e, c) {
        var keycode;
        if (window.event) keycode = window.event.keyCode;  
        else if (e) keycode = e.which;  
        if (keycode == 40) { c.translate(0, 10)}; //{circle[4] = c._.ty};// down  
        if (keycode == 39) { c.translate(10, 0)}; // right  
        if (keycode == 38) { c.translate(0, -10)}; // up  
        if (keycode == 37) { c.translate(-10, 0)}; // left  
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code, which takes two version identifiers in the form 1, 5,
Here’s a problem I’ve really been struggling with. I need to merge two sorted
Here's a problem I ran into recently. I have attributes strings of the form
Here's a coding problem for those that like this kind of thing. Let's see
Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE
Here is a synopsis of my code which is a moderately complex WinForms GUI.
Here I had a problem that I am adding contact from the address book
Here a simple question : What do you think of code which use try
Here is another spoj problem that asks how to find the number of distinct
here is my problem: I have a jList and a popup menu. When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.