1 Reply Latest reply on Oct 5, 2010 8:28 AM by kglad

    How can I get validate the checkboxes and add em to an array, please?

    combustion007 Level 1

      Hello,

       

      I have a 5 checkboxes and what I like to do is to be able to push the selected checkboxes to an array. So I have coded to check if the selected checkbox already exist in the array, if it doesn't then the selected value is pushed. The way I think I should go about is to first have the user select their answer and then there should be a submit button which will finalize all the selected values and the check if any of these values already exist in the array, and if they don't then push them into the array.

       

      Here is my code:

       

      var cbArr:Array = new Array();

       

      var gRoot = this._root;
      var main:MovieClip = gRoot.createEmptyMovieClip('mc', this.getNextHighestDepth());

       

      var mObj:Object = new Object();
      mObj.click = function(e:Object)
      {
          if(e.target.selected)
          {
             //CHECK TO SEE IF THE SELECTED VALUE ALREADY EXIST IN TH ARRAY
              if(cbArr.indexOf(e.target._name == -1))
              {
                  cbArr.push(e.target._name);
                  trace("ADDED");
                  trace(cbArr);
              }
          }
          else
          {
              e.target.label = "UNSELECTED";           
              cbArr.splice(e.target._name);
              trace(cbArr);
          }
      };

       

      for(var i:Number = 0; i < 6; i++)
      {
          main.attachMovie('CheckBox', 'cb'+i, i);
          main['cb'+i]._x = 100;
          main['cb'+i]._y = (150 + (i * 25));
          main['cb'+i]._name = "cb" + i;
         
          main['cb'+i].addEventListener("click",mObj);
      }