PDA

View Full Version : [AS2] Form Validation - Radio Groups


psypha
06-02-2009, 08:56 AM
Hello,

Does anyone have some example code to help me with a form validation procedure.

I have a questionnaire in a presentation containing 14 questions. The questions are split onto 2 frames (7 on each).
Each question has a group of five radio buttons for the user to make a choice (multiple choice quiz).

I have labelled the groupName for each radio button group.

There is a next button on the frame which will allow the user to go to the next frame. I would like to inhibit the user from proceeding to the next frame until they have completed all the questions (in other words they must select one possible option for each question).

Please would a kind person assist me

Many thanks,

Psypha:D

caseyctg
06-04-2009, 03:37 PM
import fl.controls.RadioButton;

var radio1:RadioButton = new RadioButton();
radio1.label = "none";
radio1.move(10, 10);
radio1.addEventListener(MouseEvent.CLICK, clickHandler);
radio1.addEventListener(Event.CHANGE, changeHandler);
addChild(radio1);

var radio2:RadioButton = new RadioButton();
radio2.label = "Option B";
radio2.move(10, 30);
radio2.addEventListener(MouseEvent.CLICK, clickHandler);
radio2.addEventListener(Event.CHANGE, changeHandler);
addChild(radio2);

var radio3:RadioButton = new RadioButton();
radio3.label = "Option C";
radio3.move(10, 50);
radio3.addEventListener(MouseEvent.CLICK, clickHandler);
radio3.addEventListener(Event.CHANGE, changeHandler);
addChild(radio3);

function clickHandler(event:MouseEvent):void {

trace("click:", event.currentTarget.label);

}

function changeHandler(event:Event):void {
//this function can be used for adding a click message
trace("change:", event.currentTarget.label);
if(event.currentTarget.label=="none")
{
//add a dynamic text field to the stage, and label its instance textBox
textBox.text = "Select a Choice Please"
}
else
{
textBox.text = "You Selected "+event.currentTarget.label;

//whatever frame you need to stop at
this.gotoAndStop(1);

trace("click:", event.currentTarget.label);

}
}

caseyctg
06-04-2009, 03:39 PM
what I would do is make the next button invisible if the radio is on none, if its not, then make it visible. Do this with the if else statement as above.

if(event.currentTarget.label=="none")
{ nextbutton.visible=false;
textBox.text = "Select a Choice Please"
}
else
{
textBox.text = "You Selected "+event.currentTarget.label;
nextbutton.visible=true;
//whatever frame you need to stop at
this.gotoAndStop(1);

trace("click:", event.currentTarget.label);

}

caseyctg
06-04-2009, 03:43 PM
see attached