This topic is locked
[SOLVED]

 JAVASCRIPT ON LOAD ON THE FLY

11/13/2012 4:08:25 AM
PHPRunner General questions
C
chrispa author

hI I USE FOLLOWING JAVASCRIPT TO GET ONLOAD THE SUM OF FIELDS 0000 AND 0030 ON THE FLY.

IT IS WORKING FINE WHEN I USE NUMERIC FIELDS FOR 0000 AND 0030 .

WHAT I NEED IS TO HAVE CHECKBOX ON 0000 AND 0030 AND WHEN IS CLICKED TO GET VALUE 1 NOT CLICKED VALUE 0.

SO WHEN I CLICK ON EDIT PAGE BOTH 0000 AND 0030 TO GET ON THE FLY FOR REST FIELD VALUE 2 .

ALSO ON VIEW PAGE TO SEE the checkbox either clicked or not.
var ctrlrest = Runner.getControl(pageid, 'rest');
var ctrlwork = Runner.getControl(pageid, 'work');
var ctrl0000 = Runner.getControl(pageid, '0000');
var ctrl0030 = Runner.getControl(pageid, '0030');
var sum=0;

sum=(Number(ctrl0000.getValue()) +Number(ctrl0030.getValue()));

ctrlrest.setValue(sum);
ctrlrest.on('keyup', func);
ctrlwork.on('keyup', func);
ctrl0000.on('keyup', func);

ctrl0030.on('keyup', func);

C
cgphp 11/13/2012

Try to reformulate your question showing us a couple of screenshot.

C
chrispa author 11/13/2012



Try to reformulate your question showing us a couple of screenshot.


ok you are correct is not clear what i need .
let me be more clear
i have two fields
lets say field 1

and field 2

which are checkboxes .
i see in mdb that when i click the field1 and save the record the value on the table is 1 if not clicked the value is 0

same with field2
i need on the fly to get the sum of these two fields i.e. when on add or edit page i click them to get on field3 the sum of field1+field2
hope now is clear
i know how to do it with normal numeric fields but with checkboxes is not working
can you help?

W
wildwally 11/13/2012

var ctrlname1 = Runner.getControl(pageid, 'field1');
ctrlname1.on('change', function(e){

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

{
//Do this if checkbox checked
}

});
This will determine if the check box is checked or not - use this to assign a value to a var and add the var's to determine what you want with the two sums.
Something like this



var ctrlname1 = Runner.getControl(pageid, 'field1');

var ctrlname2 = Runner.getControl(pageid, 'field2');
ctrlname1.on('change', function(e){

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

{

var sum1 = 1;

}

});
ctrlname2.on('change', function(e){

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

{
var sum2 = 1;

}

});
if(sum1 + sum2 == 2)
{
//Do This
}else{
//Do This because they didn't equal 2
}


Not tested - but should work

C
cgphp 11/13/2012

You are using the var keyword in the wrong way and the sum control is executed only one time. Check this version:



var ctrlname1 = Runner.getControl(pageid, 'field1');

var ctrlname2 = Runner.getControl(pageid, 'field2');
var sum1 = 0, sum2 = 0;
function checkSum()

{

var total = sum1 + sum2;
if(total == 2)

{

//do seomething

}

else

{

//do seomething

}

}
ctrlname1.on('change', function(e){

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

{

sum1 = 1;

checkSum();

}

});
ctrlname2.on('change', function(e){

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

{

sum2 = 1;

checkSum();

}

});
W
wildwally 11/13/2012

Thanks for correcting my mistakes (multiple).

C
chrispa author 11/14/2012



You are using the var keyword in the wrong way and the sum control is executed only one time. Check this version:



var ctrlname1 = Runner.getControl(pageid, 'field1');

var ctrlname2 = Runner.getControl(pageid, 'field2');
var sum1 = 0, sum2 = 0;
function checkSum()

{

var total = sum1 + sum2;
if(total == 2)

{

//do seomething

}

else

{

//do seomething

}

}
ctrlname1.on('change', function(e){

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

{

sum1 = 1;

checkSum();

}

});
ctrlname2.on('change', function(e){

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

{

sum2 = 1;

checkSum();

}

});




\
thank you very much both of you !!!!!