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 7994221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:04:39+00:00 2026-06-04T14:04:39+00:00

the desired behavior is when the document loads, canvas draws image 0. when the

  • 0

the desired behavior is when the document loads, canvas draws image 0. when the invisible div is clicked, canvas draws image 1, on mouseup or mouseout, it reverts back to image 0.

I left the css out because I got that working…just need to know what I’m doing wrong with the javascript function. right now it doesn’t display anything, not even the first image.

<!DOCTYPE HTML>
<html>
    <head>
        <script type="text/javascript">
        function imgChange(imagePath)
            var c=document.getElementById("myCanvas");
            var ctx=c.getContext("2d");
            var img=new Image();
            img.onload = function(){
            ctx.drawImage(img,0,0);
            };
            img.src=imagePath; <!-- I THINK THIS IS WRONG?
        </script>
    </head>

    <body>

            <canvas id="myCanvas" width="506" height="319"
onload="imgChange('0.gif')" style="border:1px solid #c3c3c3;">
            Your browser does not support the canvas element.
            </canvas>



            <div id="button1" onMouseDown="imgChange('1.gif')" onMouseUp="imgChange('0.gif')" onMouseOut="imgChange('0.gif')"></div>
            <div id="key2"></div>




    </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-06-04T14:04:41+00:00Added an answer on June 4, 2026 at 2:04 pm

    your code is missing an ending block

    function imgChange(imagePath) {
                var c=document.getElementById("myCanvas");
                var ctx=c.getContext("2d");
                var img=new Image();
                img.onload = function(){
                      ctx.drawImage(img,0,0);
                };
                img.src=imagePath;
    }
    

    The last ‘}’ is missing

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example of failure: http://progamonth.com/files/testfile.html Desired Behavior: Ideally, any headers with a colspan shouldn't affect
Desired Behavior: After using the Like button on top of my fan page, I
I'm having trouble getting desired behavior in a WPF RichTextBox. I am creating a
Desired behavior An undecorated non-nullable value-type property in a model automatically gets a validation
The desired behavior is akin to the mirrored text editing field provided in Excel
I am having problems getting the desired behavior out of these few classes and
Desired behavior: In Clojure's implementation of Agents, to update an Agent, one does NOT
With this I'd like to change the default select behavior for a document. I
I have a strange redirects. Desired behavior is: when I type URL http://xyz.localhost there
Desired Workflow First I wish to fetch a particular set of questions and answers

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.