This topic is locked

Calculain fields

7/6/2011 7:49:53 AM
PHPRunner General questions
F
futo author

calculate fields on the fly
I have next code on add/eddit page:

var ctrlCijena1 = Runner.getControl(pageid, 'Cijena1');

var ctrlKolicina1 = Runner.getControl(pageid, 'Kolicina1');

var ctrlIznos1 = Runner.getControl(pageid, 'Iznos1');



function func() {

if ( ctrlCijena1.getValue()!='' && ctrlKolicina1.getValue() && !isNaN(ctrlCijena1.getValue()) && !isNaN(ctrlKolicina1.getValue()))

ctrlIznos1.setValue(parseFloat(ctrlCijena1.getValue()) * parseFloat(ctrlKolicina1.getValue()));

else

ctrlIznos1.setValue('');

};



ctrlCijena1.on('keyup', func);

ctrlKolicina1.on('keyup', func);


Problem is if I have in that field two numbers behind coma (etc 10,30) I must press "dot" instead "coma", and on list/view page that field is shown zero /0/. Onli if is rounded number everything is shown fine.
Thanks
PHPRunner 5.3 7474

C
cgphp 7/6/2011

You have to use the js "replace" function to replace commas with dots:

var ctrlCijena1 = Runner.getControl(pageid, 'Cijena1');

var ctrlKolicina1 = Runner.getControl(pageid, 'Kolicina1');

var ctrlIznos1 = Runner.getControl(pageid, 'Iznos1');



function func() {

if ( ctrlCijena1.getValue()!='' && ctrlKolicina1.getValue() && !isNaN(ctrlCijena1.getValue()) && !isNaN(ctrlKolicina1.getValue()))

ctrlIznos1.setValue(parseFloat(ctrlCijena1.replace(",", ".").getValue()) * parseFloat(ctrlKolicina1.replace(",", ".").getValue()));

else

ctrlIznos1.setValue('');

};



ctrlCijena1.on('keyup', func);

ctrlKolicina1.on('keyup', func);


In the database, the type of Cijena1 and Kolicina1 must be decimal(5,2)

F
futo author 7/7/2011



You have to use the js "replace" function to replace commas with dots:

var ctrlCijena1 = Runner.getControl(pageid, 'Cijena1');

var ctrlKolicina1 = Runner.getControl(pageid, 'Kolicina1');

var ctrlIznos1 = Runner.getControl(pageid, 'Iznos1');
function func() {

if ( ctrlCijena1.getValue()!='' && ctrlKolicina1.getValue() && !isNaN(ctrlCijena1.getValue()) && !isNaN(ctrlKolicina1.getValue()))

ctrlIznos1.setValue(parseFloat(ctrlCijena1.replace(",", ".").getValue()) * parseFloat(ctrlKolicina1.replace(",", ".").getValue()));

else

ctrlIznos1.setValue('');

};
ctrlCijena1.on('keyup', func);

ctrlKolicina1.on('keyup', func);


In the database, the type of Cijena1 and Kolicina1 must be decimal(5,2)


**

In the database fields are decimal, i have write your code, above, but now dont calculate ....

C
cgphp 7/7/2011

Sorry. This is the right code:

var ctrlCijena1 = Runner.getControl(pageid, 'Cijena1');

var ctrlKolicina1 = Runner.getControl(pageid, 'Kolicina1');

var ctrlIznos1 = Runner.getControl(pageid, 'Iznos1');



function func() {

if ( ctrlCijena1.getValue()!='' && ctrlKolicina1.getValue() && !isNaN(ctrlCijena1.getValue()) && !isNaN(ctrlKolicina1.getValue()))

ctrlIznos1.setValue(parseFloat(ctrlCijena1.getValue().replace(",", ".")) * parseFloat(ctrlKolicina1.getValue().replace(",", ".")));

else

ctrlIznos1.setValue('');

};



ctrlCijena1.on('keyup', func);

ctrlKolicina1.on('keyup', func);


In the database the fields should be decimal(5,2) not only decimal. You have to set the length to 5,2