This topic is locked
[SOLVED]

 JavaScript Onlod

11/30/2016 4:23:05 PM
PHPRunner General questions
E
edgarv author

Hello,
with some help from this forum I was able to get my JavaScript that calculates two fields on the fly going. this work but the user has to click on the field so that the script works, I was wondering if there is a way to run the script when the page loads or if the user hovers over the save button?
tried to change the "keyup" to load, mouseover, and a few others but none of these seem to work,
my code looks like this
any help is much appreciated


var ctrlPrice = Runner.getControl(pageid, 'TIMOUT');
var ctrlQuantity = Runner.getControl(pageid, 'TIMEIN');
var ctrlTotal = Runner.getControl(pageid, 'TOTTIM');

function func() {
ctrlTotal.setValue(Number((ctrlPrice.getValue()) - Number(ctrlQuantity.getValue()))/100);
};

ctrlTotal.on('keyup', func);
jadachDevClub member 11/30/2016

Do your keyup function on ctrlQuantity

E
edgarv author 12/1/2016



Do your keyup function on ctrlQuantity


Hi jadach,
I did try that, but all the fields are read only, I am just showing the user their time in, time out and total time. If I make the field a text field, then yes, it does work if I go to the ctrlQuantity or any other field that I assign.

what I am trying to do is that when the page loads the JavaScript runs without user interaction. Or if there has to be user interaction then execute the JavaScript when hover over the submit button or when clicking the submit button, I keep playing around with it but no luck yet

jadachDevClub member 12/1/2016

If the fields are read only, then why not do the calculation in the sql editor? No need for javascript if you are not changing values on the form.

E
edgarv author 12/1/2016



If the fields are read only, then why not do the calculation in the sql editor? No need for javascript if you are not changing values on the form.


The fields get populated in the Edit as with the value of for the time out field the time in is a set time strftime("%H%M") so the sql would only look at the time in field because the time out is not yet populated. Hope this makes sense

jadachDevClub member 12/1/2016

I see. There is always more to the story than what you think.

Sergey Kornilov admin 12/1/2016

I'm with Jerry here - calculation in SQL Query should work just fine. If we are talking about Edit page - SQL Query is executed when Edit page is loaded. If we are talking about Add page - setting a default value will work. I just don't see how Javascript is relevant here.

E
edgarv author 12/2/2016



I'm with Jerry here - calculation in SQL Query should work just fine. If we are talking about Edit page - SQL Query is executed when Edit page is loaded. If we are talking about Add page - setting a default value will work. I just don't see how Javascript is relevant here.


Unfortunately id does not work because only one of the fields is populated "time in", the other field "time out" gets populated via the Editor then double clicking on the filed and typing

"strftime("%H%M")" for the default value
This is the reason I need to use a JavaScript

E
edgarv author 12/9/2016

After testing and trial and error I found the answer, after my script



var ctrlPrice = Runner.getControl(pageid, 'TIMOUT');
var ctrlQuantity = Runner.getControl(pageid, 'TIMEIN');
var ctrlTotal = Runner.getControl(pageid, 'TOTTIM');

function func() {
ctrlTotal.setValue(Number((ctrlPrice.getValue()) - Number(ctrlQuantity.getValue()))/100);
};


I added



window.onload = func;


this did gives me the result I was looking for.
I appreciate the input thank you!!