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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:57:11+00:00 2026-06-14T00:57:11+00:00

This is driving me crazy and I have no idea what is causing the

  • 0

This is driving me crazy and I have no idea what is causing the issue. I have two arrays, one which lists the pageID and the other that lists the pages.

When I try using the following code the ‘page’ always sends back ‘front’. If I put an alert during the for loop before I declare the variable “var newObject” the output is correct and the pages show “front, insideLeft, insideRight and back”.

All other attributes are outputted correctly.

Please find below my code:

    var pageID = ["cardFront","cardInsideL","cardInsideR","cardBack"];
    var pages = ["front","insideLeft","insideRight","back"];

    for (var i=0; i<pageID.length; i++) {
        var cfTextarea = $('#' + pageID[i] + ' textarea'); //array of textareas

        //Get each textarea properties and encode to json
        $("#" + pageID[i] + " textarea").each(function(){

        var txtOffset = $(this).offset();
        var divOffset = $("#" + pageID[i]).offset();

        var newObject = { 
            'page'      : pages[i],
            'id'        : $(this).attr('id'),
            'src'       : $(this).attr('src'),
            'width'     : $(this).width(),
            'height'    : $(this).height(),
            'top'       : txtOffset.top - divOffset.top,
            'left'      : txtOffset.left - divOffset.left,
            'rotation'  : '0',
            'colour'    : $(this).css("color"),
            'size'      : $(this).css("font-size"),
            'bold'      : $(this).css("font-weight"),
            'underline' : $(this).css("text-decoration"),
            'align'     : $(this).css("text-align"),
            'font'      : $(this).css("font-family"),
            'text'      : $(this).val() 
        };
        data.textareas.push(newObject);
        });
    }
  • 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-14T00:57:12+00:00Added an answer on June 14, 2026 at 12:57 am

    The problem is that the function you pass to each will only ever get i=0.

    You can work around this by doing this (untested, but this is the standard approach):

    function mk_add_text_area(data, page_id, page) {
        return function(elem) {
            var txtOffset = $(elem).offset();
            var divOffset = $("#" + page_id).offset();
    
            var newObject = { 
                'page'      : page,
                'id'        : $(elem).attr('id'),
                'src'       : $(elem).attr('src'),
                'width'     : $(elem).width(),
                'height'    : $(elem).height(),
                'top'       : txtOffset.top - divOffset.top,
                'left'      : txtOffset.left - divOffset.left,
                'rotation'  : '0',
                'colour'    : $(elem).css("color"),
                'size'      : $(elem).css("font-size"),
                'bold'      : $(elem).css("font-weight"),
                'underline' : $(elem).css("text-decoration"),
                'align'     : $(elem).css("text-align"),
                'font'      : $(elem).css("font-family"),
                'text'      : $(elem).val() 
            };
            data.textareas.push(newObject);
        }
    }
    

    then later on…

        //Get each textarea properties and encode to json
        $("#" + pageID[i] + " textarea").each(mk_add_text_area(data, pageID[i], pages[i]));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one's driving me crazy... I have a loop which adds an event listener
This is driving me crazy. I have a PHP script that gets some data
Ok, this is driving me crazy. I have a CA that needs to know
This is driving me CRAZY. I have a workbook/sheet that I refer to via
This is driving me crazy. I have an extension which we use to alter
I currently have my head wrapped around this issue - its driving me crazy.
This is driving me crazy. I have this one php file on a test
Ok, this is driving me crazy...I have this one liner to find files with
This is driving me crazy. I have library A which in turn includes library
This is driving me crazy. I have a script that pulls data from a

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.