Hi, I have been working on my portfolio website like forever. I am struggling with one problem that I can not solve for nothing. Can someone please help me. I don't know what I am doing wrong.

I have two checkboxes. When selected the selected checkbox will appear in mytxt.text box. This is how I am checking that everything is working. Instead of the selected checkbox showing up in mytxt.text result it show up true and false, false and true, and if both boxex are check true and true. I am trying to get the result of the one check box that is check and for it to dispay the name. Could someone please help? I will place the code below. I have tried everything I could think of. I know it is easier to make my checkboxes into radio buttons, but I really would like to have checkboxes.

My check boxes are name apple and orange

import fl.controls.*;
import fl.controls.RadioButtonGroup;

//This sets a group name for the radio button instances.
var myradioGroup:RadioButtonGroup = new RadioButtonGroup("RadioButtonGroup");

//This assigns the radio button instances to the radio group.
cRadio1.group = myradioGroup;
cRadio2.group = myradioGroup;


//Gives labels to the checkboxes.
applecb.label="Apple";
orangecb.label="Orange";

//Event listener for the checkboxes.
applecb.addEventListener(MouseEvent.CLICK, changelist);
orangecb.addEventListener(MouseEvent.CLICK, changelist);

function changelist(event:MouseEvent):void {
    mytxt.text = "";


}

submit_btn.addEventListener(MouseEvent.CLICK, submitFunc);
var radBtns = [cRadio1,cRadio2];
var errorsNum = 0;
function submitFunc(e:MouseEvent)
{
    var finalData = "";
    var errorFlag = "Followings errors were found.\n";
    if (name_txt.text == "")
    {
        errorsNum++;
        errorFlag +=  errorsNum+". Enter ur name.\n";
    }
    if (email_txt.text == "")
    {
        errorsNum++;
        errorFlag +=  errorsNum+". Enter ur email.\n";
    }
    if (mobile.text == "")
    {
        errorsNum++;
        errorFlag +=  errorsNum+". Enter ur phone number.\n";
    }
    if (!myradioGroup.selection)
    {
        errorsNum++;
        errorFlag +=  errorsNum+". Select ur gender.\n";
    }

    if (age.selectedIndex < 0)
    {
        errorsNum++;
        errorFlag +=  errorsNum+". Select any of the course.\n";
    }
    {
    if (applecb.selected == true) mytxt.appendText(applecb.label + "\n");
if (orangecb.selected == true) mytxt.appendText(orangecb.label + "\n");
}




        if (message_txt.text == "")
    {
        errorsNum++;
        errorFlag +=  errorsNum+". Enter ur message.\n";
    }

    if (errorsNum > 0)
    {
        mytxt.text = errorFlag;
        errorFlag = "";
        errorsNum = 0;
        return false;
    }

    else
    {
        finalData += "Thank you "+name_txt.text+" for contacting me! I will call you at "+mobile.text+", "+"else I can mail you also at "+email_txt.text+" in "+applecb.selected+" response "+orangecb.selected+" of your message "+message_txt.text+"\n\n Your other information is, you're a "+myradioGroup.selection.value+" and is between "+age.value+"\nThanks";
        mytxt.text = finalData;
    }
}
Member Avatar for LastMitch

This is how I am checking that everything is working. Instead of the selected checkbox showing up in mytxt.text result it show up true and false, false and true, and if both boxex are check true and true

The code you provided doesn't work.

The issue you mention doesn't make sense:

function changelist(event:MouseEvent):void {
mytxt.text = "";
}

How can this:

mytxt.text = "";

know true or false when you never establish whether it's true or false in the beginning.

It should look something like this:

submit_btn.addEventListener(MouseEvent.CLICK, _selected);
function _selected(e:MouseEvent):void{

var bool:Boolean = e.target.selected;

if(bool){
    trace("true);
    // if it's true this is where the true code begin 
}
else if{
    trace("false");
    // if it's false this is where the false code begin 
}
else{
    trace("both");
    // if it's both true/true or false/false this is where the both true/true or false/false code begin 
}
}

From this:

function changelist(event:MouseEvent):void {
mytxt.text = "";
}

it should look like this:

function changelist(event:MouseEvent):void { 
applecb.enabled = event.target.selected; 
orangecb.enabled = event.target.selected;     
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.