This topic is locked
[SOLVED]

 enable field when checkbox checked

3/12/2012 4:46:00 PM
PHPRunner General questions
S
stiven author

Hello everyone,
I have a field that is disabled when the page loads but i want to enabled the field when the user checks the check box this is the code but it's not working, no error in firebug



var ctrlPadre = Runner.getControl(pageid, 'clergy');

ctrlPadre.setDisabled();
var ctrlCura = Runner.getControl(pageid, 'padre');
ctrlCura.on('change', function(e){

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

ctrlPadre.setEnabled();

}

else{

ctrlPadre.setDisabled();

}
});


thanks for your help

C
cgphp 3/12/2012

The code looks correct. Are you sure you are not inverting the field name? Try to run the following code:

var ctrlPadre = Runner.getControl(pageid, 'padre');

ctrlPadre.setDisabled();
var ctrlCura = Runner.getControl(pageid, 'clergy');
ctrlCura.on('change', function(e){

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

ctrlPadre.setEnabled();

}

else{

ctrlPadre.setDisabled();

}
});
S
stiven author 3/12/2012

yes I am 100% sure.. 'padre'' is the check box and 'clergy' is the text field that is disabled.
Ii tried doing this too
if(document.getElementById('value_padre_1_0').checked == true){

ctrlPadre.setEnabled();

}
but still doesn't work :/ though with this i get this on google chrome
event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future



The code looks correct. Are you sure you are not inverting the field name? Try to run the following code:

var ctrlPadre = Runner.getControl(pageid, 'padre');

ctrlPadre.setDisabled();
var ctrlCura = Runner.getControl(pageid, 'clergy');
ctrlCura.on('change', function(e){

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

ctrlPadre.setEnabled();

}

else{

ctrlPadre.setDisabled();

}
});


C
cgphp 3/12/2012

Can you post a demo link?

S
stiven author 3/13/2012

I got it to work thanks this was the problem
ctrlCura.on('change', function(e){

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

ctrlPadre.setEnabled();

}
here I am getting the value of the checkbox not if it is actually checked so i replaced it with this
ctrlCura.on('change', function(e){

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

ctrlPadre.setEnabled();

}
yes = the value of the checkbox.. its working now
thanks