0

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;
    }
}
2
Contributors
1
Reply
13
Views
4 Years
Discussion Span
Last Post by LastMitch
0

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;     
}

Edited by LastMitch: grammer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.