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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:06:59+00:00 2026-05-20T21:06:59+00:00

EDIT I’ve figured out what was wrong. If you want to see if you

  • 0

EDIT I’ve figured out what was wrong. If you want to see if you can find it too, feel free. Otherwise I posted the answer in the answers.

I’ll go ahead and post all of the code since I’ve asked this question before but left out the things I thought were unnecessary to finding the problem, but the answerers wanted all of the code.

The following code is modeled after some other code of mine that works perfectly fine, but in this method it does not want to work. I have an initial div called #container which is an image of an Oklahoma map, and on that image you see different segments of the state. In my old code, when a user clicks in certain area of a segment, it would toggle the #container div off and toggle on a div of an image of a ‘zoomed in’ picture of that segment. After my new code which is supposed to make my code more concise, it will not toggle the #container off (and I suspect not toggle the new div on).

I determine which segment (#region) to turn on by using mouse position when the user clicks. I use pixel coordinates, and I have done the math to scale those coordinates so it doesn’t matter what the screen size is.

And now, here is the new and buggy code:

$(document).ready(function()
{


//Main Oklahoma map
$("#container").click(function(e)
{
    var x = event.pageX;
    var y = event.pageY;

    const scaling_Screen_Max_Pixel_X = 1679;
    const scaling_Screen_Max_Pixel_Y = 924;

    // Math for the scaling of different sized windows
    var currentX = $(document).width();
    var currentY = $(document).height();
    var xScale = currentX/scaling_Screen_Max_Pixel_X;
    var yScale = currentY/scaling_Screen_Max_Pixel_Y;

    // Variables for different regions
    var zoneX = x/xScale;
    var zoneY = y/yScale;

    // Arrays containing the min and max x and y values of the rectangular area around a farm
    var minX = [47, 593, 593, 958, 600, 744, 852, 1025, 1060, 1159, 1366];
    var maxX = [553, 958, 792, 1011, 1124, 1124, 1149, 1598, 1280, 1623, 1551];
    var minY = [250, 250, 473, 349, 526, 665, 495, 248, 471, 520, 481];
    var maxY = [330, 473, 515, 478, 665, 721, 526, 471, 500, 763, 520];

    var regionNumber = [1,2,2,2,3,3,3,4,4,5,5];

    /** Loops through the values within the coordinate arrays to
        determine if the user clicked within a certain area **/
    for (var i = 0; i < minX.length; i++)
    {
        if(zoneX >= minX[i] && zoneX <= maxX[i] && zoneY >= minY[i] && zoneY <= maxY[i]) 
        {
            $("#region"+region[i]).toggle();
            $("#container").toggle(); //toggle off
        }
    }
   }); 
 });

The coordinates in the minX, maxX, etc. arrays are in order, so the first element in each of those four arrays belong to the first region (#region1). The reason I have the regionNumber array is because I have more than one “rectangle” set of coordinates for some regions because the regions are not perfectly rectangular.

As I’ve said before, nothing happens when I click a region. Do you see what the problem is here?

  • 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-20T21:07:00+00:00Added an answer on May 20, 2026 at 9:07 pm

    OOPS! While sitting here staring at my code, I realized what the problem was. I forgot to say $("#region"+regionNumber[i]).toggle(); instead of $("#region"+region[i]).toggle();.

    Now it works just fine. Thanks for looking everyone!

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

Sidebar

Related Questions

EDIT: See my answer below--> I am wanting to have a view that when
EDIT : It turned out that this can only be done through an external
Edit 4: I was finally able to solve my own issue. See checkmark answer
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
Edit : Note that, as Daniel and latkin noted in an answer and a
EDIT: Simple version of the question: I want to create server variables in the
(EDIT: I have asked the wrong question. The real problem I'm having is over
Edit : Though I've accepted David's answer, Jon's answer should be considered as well.
Edit - please see bottom. I've got a primefaces calendar component on my page.
EDIT: You can use unsafe code... you just have to manually edit the proj

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.