This topic is locked
[SOLVED]

 How to make a field required depending on an other field

1/17/2012 1:24:17 PM
PHPRunner General questions
N
Nelson author

Hi,
I'm trying to make a field required only if a user chooses a alternative on another field, something like exampel below:
field1: Type of the building

field2: House number
field1, type of the building has 2 alternatives: 1-House 2-Apartment
I the field2(House number) become required only if the user chooses alternative 1- House on the field1
I have this scrpit which I was testing on javasc on load (events):

var ctrl1 = Runner.getControl(pageid, 'Type of the building');

var ctrl2 = Runner.getControl(pageid, 'House number');

if (ctrl1.getValue()=='House'){

ctrl2.addValidation("IsRequired");

}


But it gives no effect!
Can someone please help me with this, thanks.

C
cgphp 1/17/2012
var ctrl1 = Runner.getControl(pageid, 'Type of the building');

var ctrl2 = Runner.getControl(pageid, 'House number');
ctrl1.on('change',function(e){

if(this.getValue() == 'House')

ctrl2.addValidation("IsRequired");

else

ctrl2.removeValidation("IsRequired");

});


Make sure that the value of the field1 is a string and not an integer value like an ID.

N
Nelson author 1/17/2012


var ctrl1 = Runner.getControl(pageid, 'Type of the building');

var ctrl2 = Runner.getControl(pageid, 'House number');
ctrl1.on('change',function(e){

if(this.getValue() == 'House')

ctrl2.addValidation("IsRequired");

else

ctrl2.removeValidation("IsRequired");

});


Make sure that the value of the field1 is a string and not an integer value like an ID.


Thank you so much Sir,
That solved it