This topic is locked
[SOLVED]

 Different in Hour and minutes JavaScript Onload

11/4/2016 10:26:26 AM
ASPRunnerPro General questions
anderson810311 author

I have 3 fields in a add page: hora_inicial and hora_final and tempo. I would like to calculate how match is the different in Hour and minutes and show the result in the tempo field.
This is my code on the Javascript on load event, but is dosn´t work
var ctrlPrice = Runner.getControl(pageid, 'hora_inicial');

var ctrlQuantity = Runner.getControl(pageid, 'hora_final');

var ctrlTotal = Runner.getControl(pageid, 'tempo');
function func() {
ctrlTotal.setValue(ctrlQuantity.getValue()- ctrlPrice.getValue());
};
ctrlPrice.on('keyup', func);

ctrlQuantity.on('keyup', func);
any help?
Ex:
I have three fields:
1º hora_inicial

2º hora_final

3º tempo
hora_inicial = 02:00

hora_final = 02:30

tempo = 00:30
Subtract = 02:00 - 02:30 = 00:30
I wanted automatically once put hora_inicial and hora_final it me automatically return to javascript difference in time.

admin 11/4/2016

You need to convert those values to date object, calculate the difference and convert the difference into minutes.
Check the first answer here for inspiration:

http://stackoverflow.com/questions/1787939/check-time-difference-in-javascript

anderson810311 author 11/5/2016



You need to convert those values to date object, calculate the difference and convert the difference into minutes.
Check the first answer here for inspiration:

http://stackoverflow.com/questions/1787939/check-time-difference-in-javascript


Please, Can you show me how to PHPRunner? at the javascript onload?

admin 11/7/2016

You can do this in PHPRunner exactly the same way you would do that in plain Javascript. There is nothing PHPRunner-specific here and you can see an example of doing that at http://stackoverflow.com/questions/1787939/check-time-difference-in-javascript
If you have a support contract you can contact support team directly at http://xlinesoft.com/dss/support.asp

anderson810311 author 11/14/2016



You can do this in PHPRunner exactly the same way you would do that in plain Javascript. There is nothing PHPRunner-specific here and you can see an example of doing that at http://stackoverflow.com/questions/1787939/check-time-difference-in-javascript
If you have a support contract you can contact support team directly at http://xlinesoft.com/dss/support.asp


Solved, thanks <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=80673&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
function func() {
var start = ctrlPrice.getValue();//'8:00';

var end = ctrlQuantity.getValue();//'23:30';
s = start.split(':');

e = end.split(':');
min = e[1]-s[1];

hour_carry = 0;

if(min < 0){

min += 60;

hour_carry += 1;

}

hour = e[0]-s[0]-hour_carry;

diff = hour + ":" + min;

if (hour < 10 ){

diff = "0"+hour + ":" + min;

}

if ( min < 10){

diff = hour + ":"+"0"+ min;

}
ctrlTotal.setValue(diff);
//var val2 = (ctrlQuantity.getValue() - ctrlPrice.getValue());

//ctrlTotal.setValue(val2.toFixed(2));

if (min > 20){

tempo.show();

tempo.addValidation("IsRequired");

} else {

tempo.setValue("");

tempo.hide();

tempo.removeValidation('IsRequired');

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

ctrlQuantity.on('keyup', func);