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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:23:25+00:00 2026-05-30T19:23:25+00:00

I am using Jquery to grab the input value as numbers are typed in

  • 0

I am using Jquery to grab the input value as numbers are typed in it. As well as drawing out circles on a div #canvas_container with raphaeljs based on the number inputted. Currently I am trying to set a maximum input value like if (value <= 50) { where value is the input of the user.

What I want to achieve eventually is if the user types in 30, 30 circles are drawn. If the user types in 60 or any value 50 and above 50 circles are drawn. Creating a maximum amount of circles drawn to the canvas_container. Right now I am just trying to get nothing to happen when any value 50 and above is inputted, but some circles are drawn but only a few, I am not sure why.

http://jsfiddle.net/anderskitson/sHNHe/9/

var paper = new Raphael(document.getElementById('canvas_container'), 500, 500);
$("input").keyup(function() {
    var value = $(this).val();

    if (value <= 50) {

    if (value === "") {
        var circle = paper.circle(110, 50, 30);
        var clear = paper.clear();
    } else {

        for (i = 0; i <= value; i++) {

            var randomNumber1 = Math.floor(Math.random() * 201) - 100;
            var randomNumber2 = Math.floor(Math.random() * 201) - 100;

            var plusOrMinus = Math.random() < 0.5 ? -1 : 100;

            var circle = paper.circle(randomNumber1, randomNumber2, 20);
        }
    }

    }else {
        //this should run if a value of 50 or above is entered
        }

}).keyup();
  • 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-30T19:23:26+00:00Added an answer on May 30, 2026 at 7:23 pm

    As far as I can see, you’ve got two errors:

    1. You need to clear your paper on every keyup, else the new circles will be added to the “old” ones on every keyup()
    2. Your handling if value > 50 is a bit complicated

    Let’s fix that (in a simplified version):

    var paper = new Raphael(25, 25, 500, 500);
    $("input").keyup(function() {
        var value = parseInt($(this).val());
        paper.clear();
    
        if (value > 50) {
            value = 50;
        }
    
        for (i = 0; i < value; i++) {
    
            var randomNumber1 = 50 + 5 * i;
            var randomNumber2 = 50 + 5 * i;
    
            var circle = paper.circle(randomNumber1, randomNumber2, 20);
        }
    });​
    

    Have a look at the Fiddle, I hope this is what you wanted to achieve.

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

Sidebar

Related Questions

I am using jQuery to grab the ID of a DIV Tag and then
I am having trouble accessing the value of an HTML Input element using jQuery,
well I havn't really ever using jquery to grab data from a server.. and
I'm using a function which utilizes jQuery in order to grab information from a
I've got an input like so: I'd like to use jQuery to grab that
I was trying to grab some data from the database using JQuery AJAx, and
Here is what I have <form> <input type=text name=item1 class=grab value=userInput /> <input type=text
I am using Jquery .keyup and .val to grab what I type into a
I am using jQuery to grab results from a webservice(3rd party can't change). A
I'm using jQuery to grab some JSON data. I've stored it in a variable

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.