I’m in trouble with a form (poll type). It’s already done i just have this little problem that i dont know how to validate enabled input field by a checkbox.
I got 4 checkboxes each of them enabling/disabling its own input field when checked/unchecked. This for a little explanation of the user’s choice. So i need to validate if the enabled input text has some text in it, if not, restrict the submit of the form (by button).
I tried something like this:
} else if (checkBox1_txt.enabled = true || checkBox1_txt.text ="") {
status_txt.text = "Please, explain your choice";
} else if (checkBox1_txt.enabled = true && checkBox1_txt.text ="") {
status_txt.text = "Please, explain your choice";
or…
} else if (checkBox1_txt.enabled = true || checkBox1_txt.length) {
status_txt.text = "Please, explain your choice";
} else if (checkBox1_txt.enabled = true && checkBox1_txt.length) {
status_txt.text = "Please, explain your choice";
But isn’t working, it gets stucked in “Please, explain your choice”. I would appreciate it a lot if anyone can help me
Here’s the AS3 (php is collectin/runin fine)
processing_mc.visible = false;
//--------------Setup vars
var checkBxGroup:String="";
//--------------Set checkboxes for checkBxGroup
checkBox1.addEventListener(MouseEvent.CLICK, changeHandler_checkBxGroup);
checkBox2.addEventListener(MouseEvent.CLICK, changeHandler_checkBxGroup);
checkBox3.addEventListener(MouseEvent.CLICK, changeHandler_checkBxGroup;)
checkBox4.addEventListener(MouseEvent.CLICK, changeHandler_checkBxGroup);
function changeHandler_checkBxGroup(event:Event):void {
checkBxGroup=event.currentTarget.label;
}
//--------------Build variable name for the URL variables loader
var variables:URLVariables = new URLVariables;
//--------------Build the varSend variable
var varSend:URLRequest = new URLRequest("sender.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
//--------------Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
//--------------Handler for the PHP script completion and return of status
function completeHandler(event:Event):void {
//--------------Remove processing
processing_mc.visible = false;
//--------------checkboxes
checkBox1.selected = false;
checkBox2.selected = false;
checkBox3.selected = false;
checkBox4.selected = false;
//--------------inputs
checkBox1_txt.text = "";
checkBox2_txt.text = "";
checkBox3_txt.text = "";
checkBox4_txt.text = "";
// Load the response from php
status_txt.text = event.target.data.return_msg;
//--------------enable/disable input 1 on checkbox1 checked
checkBox1.addEventListener(MouseEvent.CLICK , enableTxt1);
checkBox1_txt.enabled = false
function enableTxt1(event:MouseEvent):void {
checkBox1_txt.enabled = event.target.selected;
checkBox1_txt.text = "";
}
//--------------enable/disable input 2 on checkbox2 checked
checkBox2.addEventListener(MouseEvent.CLICK , enableTxt2);
checkBox2_txt.enabled = false
function enableTxt2(event:MouseEvent):void {
checkBox2_txt.enabled = event.target.selected;
checkBox2_txt.text = "";
}
//--------------enable/disable input 3 on checkbox3 checked
checkBox3.addEventListener(MouseEvent.CLICK , enableTxt3);
checkBox3_txt.enabled = false
function enableTxt3(event:MouseEvent):void {
checkBox3_txt.enabled = event.target.selected;
checkBox3_txt.text = "";
}
//--------------enable/disable input 4 on checkbox4 checked
checkBox4.addEventListener(MouseEvent.CLICK , enableTxt4);
checkBox4_txt.enabled = false
function enableTxt4(event:MouseEvent):void {
checkBox4_txt.enabled = event.target.selected;
checkBox4_txt.text = "";
}
// Add event listener for submit button click
submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
// function ValidateAndSend
function ValidateAndSend (event:MouseEvent):void {
// validate checkboxes for at least one selection
if (checkBxGroup=="") {
status_txt.text = "select at least one option";
} else {
// All is good
status_txt.text = "Information completed!";
// All is good, send the data now to PHP
processing_mc.visible = true;
// ready the variables in our form for sending
variables.checkBoxs = checkBxGroup;
// Send the data to PHP now
varLoader.load(varSend);
} // close else condition for error handling
} // close validate and send function