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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:01:57+00:00 2026-05-14T19:01:57+00:00

I have created an: var checkboxFarm = new Array(); then I want to record

  • 0

I have created an:

var checkboxFarm = new Array();

then I want to record a checkbox status in that array, as there are 11 checkboxes.

Button.addEventListener("click", function() {

          rp_farmAtivada(index);

        }, false);

when clicked change the variable in the array:

function rp_farmAtivada(index) {
     checkboxFarm[index] = !checkboxFarm[index];
};

but every time I refresh the page it loses all the checkboxes status and I’m aware that all that array gets the “undefined” value.

the checkboxFarm array is defined in the beginning of the script, so it should have a global scope.

Am I missing something?

  • 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-14T19:01:58+00:00Added an answer on May 14, 2026 at 7:01 pm

    You will need to save the status of the checkboxes to be able to refresh and keep their state, as HTTP is stateless.

    You could add some AJAX on click to save the results to a database, or to a cookie.

    Then on DOM ready, you could retrieve these previous results and change the checkbox values accordingly (or alternatively use a server side language to echo the default states in the markup).

    Update

    Your comment on LukeN’s answer…

    can I define the default value for all
    the array as true without setting it
    for each one?

    Yes, you can. Look at this code…

    // I'm using an empty array literal here, more succinct and widespead than the old `new Array()`
    var checkboxFarm = []; 
    
    // You will need to define here how many array members you want to have the `true` value
    for (var i = 0; i <= 10; i++) {
        checkboxFarm[i] = true;
    }
    

    See it working online at JSbin.

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

Sidebar

Related Questions

I have an array created with this code: var widthRange = new Array(); widthRange[46]
I have created a JS array like this var detailsArr = new Array(); and
I have my own asp.net cookie created like this: var authTicket = new FormsAuthenticationTicket(
I have a modal dialog that is created with the following: procedure TFormCompose.createParams(var Params:
I have created an element like this: var myDiv = new Element('div'); myDiv.update('Hello!'); I
I am new in Sencha i have created var genres = new Ext.data.Store({ autoLoad:
i have created an array in JS var myArray=[ [el1,pos1,width1,active1], [el2,pos2,width2,active2], [el3,pos4,width3,active3], [el4,pos1,width4,active4] ];
I have created an object through literals and instantiating using 'new' operator. But that's
I have created a Python script that I want to run daily via a
Im trying to grab value from label checkbox:checked. I have created this function var

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.