This topic is locked
[SOLVED]

 update a field if another field is filled

9/28/2012 4:51:41 PM
PHPRunner General questions
C
cetipabo author

Hi !

i'm using 6.1 and i'm trying something based on this manual

http://xlinesoft.com/phprunner/docs/how_to_calculate_values_on_the_fly.htm

But my problem is a little bit different, i don't want to calculate something like: Field1 x Field2 = Field3
I have 3 fields in my ADD page

Status

Field1

Field2


and i would like the satusfield immediatly updated when i open the ADD page.
If Field1is filled with some data, i would like the Statusfield to be "10"

If Field2is filled with some data, i would like the Statusfield to be "20"
I know PHP, but not javascript...so i tried a few things which never worked.

var ctrlField1 = Runner.getControl(pageid, 'Field1');

var ctrlField2 = Runner.getControl(pageid, 'Field2');

var ctrlStatus = Runner.getControl(pageid, 'Status');
function func() {

ctrlStatus.setValue(i_dont_know_what_to_put_here);

};


Also i don't know what code to use to replace this part below, keyup should not be the correct event:

ctrlField1.on('keyup', func);

ctrlField2.on('keyup', func);


I'm wondering if Javascript onload is the correct way to do what i want...i can't see which event to use for this problem...

I read this : http://xlinesoft.com/phprunner/docs/control_object.htm but i'm still confused...

Thanks for helping me!
Edit:

i'm thinking too much....why waiting for an event ??? This should work !?

var ctrlField1 = Runner.getControl(pageid, 'Field1');

var ctrlField2 = Runner.getControl(pageid, 'Field2');

var ctrlStatus = Runner.getControl(pageid, 'Status');
if (ctrlField1.getvalue()!="") ctrlStatus.setValue(10);

if (ctrlField2.getvalue()!="") ctrlStatus.setValue(20);
C
cetipabo author 10/3/2012

So finally i was pointed in the wrong direction, it's not with a javascript onload event that we have to deal but with PHP code.
In ADD PAGE, Before record added and EDIT PAGE, Before record updated :



$values["status"]=0;

if ($values["Field1"] !="")

$values["status"]=10;
if ($values["Field2"] !="")

$values["status"]=20;


When i ADD or Edit the page, the status is automaticaly inserted in the database.
IF Field1 = somethingthen Status = 10

IF Field2 = somethingthen Status = 20

IF Field1 AND Field2 have somethingin it then Status = 20

IF Both Field1 and Field2 are empty then Status = 0