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

  • SEARCH
  • Home
  • 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 8828655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:39:24+00:00 2026-06-14T07:39:24+00:00

I’m developing a web app that lets the user click a button (with a

  • 0

I’m developing a web app that lets the user click a button (with a number or mathematical symbol value) and then click in a workspace and have the corresponding character appear. So far, this is what I have for the Javascript:

<script type="text/javascript">
            var mathCanvas = document.getElementById("matharea");
            var ctx = mathCanvas.getContext("2d");
            ctx.font="18px Arial";

            var boolOne = 0;
            var boolTwo = 0;

            function insertOne(){
                boolOne = 1;
            };

            function insertTwo(){
                boolTwo = 1;
            };

            mathCanvas.onclick = function(event){
                var x = event.offsetX;
                var y = event.offsetY;
                if(boolOne == 1){
                    ctx.fillText("1",x-5,y-5);
                    boolOne = 0;
                };

                if(boolTwo == 1){
                    ctx.fillText("2",x-5,y-5);
                    boolTwo = 0;
                };
            };
</script>

Right now I’m only testing using the 1 and 2 buttons. In the two ‘if’ statements I set the boolean value back to 0 after the number is placed, but obviously it would be better to allow the user to keep placing the corresponding number until another number button is pressed, instead of the one-shot functionality I have here. I can imagine resetting the boolean when another specific button is pressed, but how would I change it back to 0 when ANY other button is pressed?

  • 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-14T07:39:25+00:00Added an answer on June 14, 2026 at 7:39 am

    You could change around your logic a little bit to make it a lot more flexible. Something like:

    var placementCallback = function() {}
    function onButton1Click() {
     placementCallback = function(x, y) {
       ctx.fillText('1', x-5,y-5);
     }
    }
    
    function onButton2Click() {
     placementCallback = function(x, y) {
       ctx.fillText('2', x-5,y-5);
     }
    }
    
    mathCanvas.onclick = function(event){
      placementCallback(event.offsetX, event.offsetY);
    }
    

    This way, you don’t have a massive if condition and you can build out as many buttons as you’d like (and it meets your “as many times as the user wants” requirement as well, provided you give their implementation for the placement callback that is.

    Hope that helps.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
I know there's a lot of other questions out there that deal with this

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.