Forums: [SOLVED] Different in Hour and minutes JavaScript Onload - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

[SOLVED] Different in Hour and minutes JavaScript Onload Rate Topic: -----

#1 User is offline   Anderson Maciel 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 04-November 16

Posted 04 November 2016 - 02:26 PM

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.

Posted Image
0

#2 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 15998
  • Joined: 03-February 03

Posted 04 November 2016 - 06:59 PM

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...e-in-javascript
Best regards,
Sergey Kornilov
0

#3 User is offline   Anderson Maciel 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 04-November 16

Posted 06 November 2016 - 01:48 AM

View Postadmin, on 04 November 2016 - 03:59 PM, said:

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...e-in-javascript


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

#4 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 15998
  • Joined: 03-February 03

Posted 07 November 2016 - 03:07 PM

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...e-in-javascript

If you have a support contract you can contact support team directly at http://xlinesoft.com/dss/support.asp
Best regards,
Sergey Kornilov
0

#5 User is offline   Anderson Maciel 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 04-November 16

Posted 14 November 2016 - 04:53 PM

View Postadmin, on 07 November 2016 - 12:07 PM, said:

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...e-in-javascript

If you have a support contract you can contact support team directly at http://xlinesoft.com/dss/support.asp



Solved, thanks :)

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);
0

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked