This topic is locked
[SOLVED]

 change values based on chekbox

10/25/2010 5:18:44 PM
PHPRunner General questions
T
tedwilder author

hello

I have a form with 3 check box ( it's to check the content of pacckets).

I'd like that if all 3 are checks : the field " result" show " COMPLETE " on the add form and value "complete " is set for field result.

if just one is not checked : the reult field shoud show " incomplete " and value set to incomplete.

can you show my how to do that? I know how to do it in php, but I dont know in javascript how to make " green " complete " or red " incomplete" change in real time when user tick the box of not.

thank you for your help.

A
ann 10/26/2010

Hi,
here is a sample code for this:

var ctrl1 = Runner.getControl(pageid, 'CheckBox1');

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

var ctrlRes = Runner.getControl(pageid, 'Result');
function func() {

if ((ctrl1.getValue=='on')&&(ctrl2.getValue()=='on')){

ctrlRes.setValue('Complete');

document.getElementById('div1').style.color = 'green';

}

else{

ctrlRes.setValue('Incomplete');

document.getElementById('div1').style.color = 'red';

}

};
ctrl1.on('click', func);



where CheckBox1,Result are your actual field names.

Here id=div1 is added in the HTMLmode on the Visual Editor tab:

{BEGIN FieldName_fieldblock}

<tr><td class=shade width=150>

{BEGIN FieldName_label}{$label userstable FieldName}{END FieldName_label}

</td><td width=250 id=div1>

{$FieldName_editcontrol}

</td></tr>

{END FieldName_fieldblock}

T
tedwilder author 10/26/2010

thanks a lot for your detailed response.

However I can't make it work.

I uploaded my project and opened a ticket.
thanks.

T
tedwilder author 10/26/2010

ok it's working now. for those interested the correct code was

if ((ctrl1.getValue()=='on')&&(ctrl2.getValue()=='on')){

ctrlRes.setValue('Complete');

thank you.