Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logic Check 1

Status
Not open for further replies.

boab

Programmer
May 30, 2001
75
GB
Folks can you have a look at the code below and tell me if I have missed something.

The Background is that in the movie clip(page5) I have 2 yes/no questions controlled by radio groups the first is in the root of the movie clip. If the user clicks no to the first question(radio_a) this reveals a movie symbol "ifno" which contains a dynamic multiline textarea "inputno"(not a component) which has "Comments" as the variable and the second question (radio_b). If the user then answers yes to the second question this reveals a second movie symbol "ifyes" which simply contains a dynamic multiline textarea "inputyes" which has Comments1 associated with it.

The problem that I am having is that I want to validate the form such that if radio_a = no then the user must enter something into the textarea "ifno" and must answer radio_b then if radio_b =yes the user must enter something into textarea "ifyes"

the code I am using is:
returnVal = true; //default value

// check if radio_a is answered
if (this.page5.radio_a.getValue() == undefined) {
returnVal = false;

} else if (this.page5.radio_a.getValue() == No) {
if (this.page5.ifno.radio_b.getValue == undefined) {
returnVal = false;
} else if (this.page5.ifno.radio_b.getValue == 'Yes')
{
if (this.page5.ifyes.inputyes=null) {
returnVal = false;
}
} else if (this.page5.ifno.inputno=null) {
returnVal = false;

}
}

the problem that I am having is that it will not validate the form at all. Any suggestions will be gratefully received[morning]


THe Start of wisdom is to realise you know nothing. I'll be a genius then!
 
Looks like you are using different syntax throughout.

If you are going to use a variable assignment for true or false you should have two different variables. One for radio_a and one for radio_b. That said I would not use a variable assignment at all but rather simply return true or false.

Since I don't have your .fla file I can only partially test this but give this a try:

Code:
_global.checkRadio = function(){
	if (this.page5.radio_a.getValue() == "No" && this.page5.ifno.getValue() == null){
		trace("Please enter a comment in the 'No' comment field");
		return false;
	}else if (this.page5.radio_b.getValue() == "Yes" && this.page5.ifyes.getValue() == null){
		trace("Please tell us why you entered yes");
		return false;
	}else{
		return true;
	}
}

Then on your submit button:

Code:
on(release){
    if(_global.checkRadio){
        //enter form action here
    }else{
        //enter alternative action here
    }
}

Let me know how it turns out!

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top