This topic is locked
[SOLVED]

 How to disable control based on another control value

10/29/2011 10:41:15 AM
PHPRunner General questions
A
acpan author

i don't seems to get it work, there is what i have done but not working.
In in add page javascript onload event:
var ctrlStatus = Runner.getControl(pageid, 'status');

var ctrlDescription = Runner.getControl(pageid, 'description');
ctrlStatus.on('change', function(e){

if (this.getValue() == 1) {

ctrlDescription.setEnabled();

ctrlDescription.setValue("ABC<br/>ENABLE");

ctrlDescription.addValidation("IsRequired");

}

else

{
ctrlDescription.setDisabled();

ctrlDescription.setValue("");

ctrlDescription.removeValidation("IsRequired");

}

});
Here's what i get:
when i first clicked on status checkbox to on, nothing happen.

then i clicked status checkbox to off, the field "description" is disabled.

then i clicked again to on, the field is still disabled,

and then after this, whatever i do, checedk on and checked off, the field stays disabled.
tried many times, still having the same problem.
anybody has any idea?

Sergey Kornilov admin 10/29/2011

Try to compare checkbox value with 'on':

...

if (this.getValue() == 'on') {

...
A
acpan author 10/29/2011

Thanks Sergey, it works.
Here's the final solution:
In in add page javascript onload event:
var ctrlstatus = Runner.getControl(pageid, 'status');

var ctrlDescription = Runner.getControl(pageid, 'description');
ctrlstatus.on('change', function(e){

if (this.getValue() == "on" ) {

ctrlDescription.setEnabled();

ctrlDescription.setValue("ABC<br/>ENABLE");

ctrlDescription.addValidation("IsRequired");

}
else {
ctrlDescription.setDisabled();

ctrlDescription.setValue("");

ctrlDescription.removeValidation("IsRequired");

}

});