onchange event
-
- Experienced User
- Posts: 147
- Joined: Tue Jun 17, 2014 4:00 pm
- First Name: Patti
- Last Name: Bednarz
- Company Name: McGard
- State / Province: New York
- Country: United States
- Contact:
onchange event
Can I force the onchange event to be activated for a field on the screen? My scenario is as follows: If a user clicks on a hyperlink, it causes a screen field value to be reset to it's default. I have an onchange event on that same screen field to cause calcualations to be performed. The onchange event works fine when the user manually changes the value in the field. It does not execute the onchange event when the javascript code from the hyperlink causes the field value to change.
This is what happens now:
link clicked, field2 changed to 7 by javascript, no calculations take place
link not clicked, field2 changed to 7 by the user, calculations take place
I need the calculations to take place either way.
Thank you,
Patti
This is what happens now:
link clicked, field2 changed to 7 by javascript, no calculations take place
link not clicked, field2 changed to 7 by the user, calculations take place
I need the calculations to take place either way.
Thank you,
Patti
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: onchange event
Put the code in your onchange event into a function. Have onchange call that function. Have something else (whatever is the other condition... clicking a hyperlink?) call the function as well.
-
- Experienced User
- Posts: 147
- Joined: Tue Jun 17, 2014 4:00 pm
- First Name: Patti
- Last Name: Bednarz
- Company Name: McGard
- State / Province: New York
- Country: United States
- Contact:
Re: onchange event
Scott,
I knew I would eventually have to create a function because I have the same javascript on a couple different fields. The problem is that the javascript re-calculates multiple fields from a grid row and then updates the row. (See "javascript calculations" entry from 11/9/16 in forum). I thought a function could only return one value. Not sure how to do all that in one function. Patti
I knew I would eventually have to create a function because I have the same javascript on a couple different fields. The problem is that the javascript re-calculates multiple fields from a grid row and then updates the row. (See "javascript calculations" entry from 11/9/16 in forum). I thought a function could only return one value. Not sure how to do all that in one function. Patti
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: onchange event
Patti,
The "return" value of a JS function can only have one value, but that value can be an object (the JS equivalent of RPG's data structure) so in that respect it can return as many values as you want.
I'm not understanding how this relates to your example from the "javascript calculations" thread, as that example doesn't return anything at all.
The "return" value of a JS function can only have one value, but that value can be an object (the JS equivalent of RPG's data structure) so in that respect it can return as many values as you want.
I'm not understanding how this relates to your example from the "javascript calculations" thread, as that example doesn't return anything at all.
-
- Experienced User
- Posts: 147
- Joined: Tue Jun 17, 2014 4:00 pm
- First Name: Patti
- Last Name: Bednarz
- Company Name: McGard
- State / Province: New York
- Country: United States
- Contact:
Re: onchange event
That's why I did not know how I could turn it into a function. That code is currently on my "onchange" event for my hours worked and my cost/hour fields. There is a hyperlink that resets the cost/hour to a default value if the user clicks. However, the since the user did not enter a value, the "onchange" for the cost/hr is not executed. I don't want to have duplicate javascript code on the 2 fields and I would like to have the hyperlink execute the javascript code as well. Hopefully, that gives a better picture of what I am trying to accomplish....
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: onchange event
I'm not having any trouble understanding your code. What I don't understand is where you're stuck? Just turn it into a function and call it from both places...
Set onchange to pattisFunction(). When the hyperlink is clicked, also run pattisFunction(). I'm not understanding what this has to do with return values, etc.
Code: Select all
function pattisFunction() {
var hrrate = pui.get("T_CstHr.1");
var hrswrk = pui.get("T_HrsWrkd.1");
var csmcst = pui.get("T_CsmCst.1");
var msccst = pui.get("T_MscCst.1");
var hidcst = pui.get("T_HidCstHr.1");
if (hrrate !== 0 && hrswrk !== 0 && hrrate !== "" && hrswrk !== "")
{
var labcstc = (hrswrk * hrrate);
var labcst = labcstc.toFixed(2);
var totcstc = (labcst + csmcst + msccst);
var totcst = totcstc.toFixed(2);
pui.set("T_LabCst.1",labcst);
pui.set("T_TotCst.1",totcst);
getObj("CostGrid").grid.refresh();
}
}
-
- Experienced User
- Posts: 147
- Joined: Tue Jun 17, 2014 4:00 pm
- First Name: Patti
- Last Name: Bednarz
- Company Name: McGard
- State / Province: New York
- Country: United States
- Contact:
Re: onchange event
Scott, I think maybe I was not understanding. I did not realize I could execute a function to do a task for a particular screen (similar to a subroutine in an rpg program). I will try it. Thanks. - Patti
-
- Experienced User
- Posts: 147
- Joined: Tue Jun 17, 2014 4:00 pm
- First Name: Patti
- Last Name: Bednarz
- Company Name: McGard
- State / Province: New York
- Country: United States
- Contact:
Re: onchange event
Scott,
I set up my function and started out by running from the hyperlink. When it attempts to execute it tells me "On Click Error updReqCost is undefined"
This is the code on the onclick event:
var hidcst = pui.get("T_HidCstHr.1");
pui.set("T_CstHr.1",hidcst);
applyProperty("T_OvrMsg", "visibility", "hidden");
applyProperty("T_OvrLnk", "visibility", "hidden");
updReqCost();
This is the function:
function updReqCost() {
var hrrate = Number(pui.get("T_CstHr.1"));
var hrswrk = Number(pui.get("T_HrsWrkd.1"));
var csmcst = Number(pui.get("T_CsmCst.1"));
var msccst = Number(pui.get("T_MscCst.1"));
var hidcst = Number(pui.get("T_HidCstHr.1"));
if (hrrate !== 0 && hrswrk !== 0 && hrrate !== "" && hrswrk !== "")
{
var labcstc = Number(hrswrk * hrrate);
alert("calc lab= " + labcstc);
var labcst = labcstc.toFixed(2);
var totcstc = Number(labcst + csmcst + msccst);
var totcst = totcstc.toFixed(2);
pui.set("T_LabCst.1",labcst);
pui.set("T_TotCst.1",totcst);
getObj("CostGrid").grid.refresh();
if (hrrate != hidcst)
{
applyProperty("T_OvrMsg", "visibility", "visible");
applyProperty("T_OvrLnk", "visibility", "visible");
}
else
{
applyProperty("T_OvrMsg", "visibility", "hidden");
applyProperty("T_OvrLnk", "visibility", "hidden");
}
}
}
}
I set up my function and started out by running from the hyperlink. When it attempts to execute it tells me "On Click Error updReqCost is undefined"
This is the code on the onclick event:
var hidcst = pui.get("T_HidCstHr.1");
pui.set("T_CstHr.1",hidcst);
applyProperty("T_OvrMsg", "visibility", "hidden");
applyProperty("T_OvrLnk", "visibility", "hidden");
updReqCost();
This is the function:
function updReqCost() {
var hrrate = Number(pui.get("T_CstHr.1"));
var hrswrk = Number(pui.get("T_HrsWrkd.1"));
var csmcst = Number(pui.get("T_CsmCst.1"));
var msccst = Number(pui.get("T_MscCst.1"));
var hidcst = Number(pui.get("T_HidCstHr.1"));
if (hrrate !== 0 && hrswrk !== 0 && hrrate !== "" && hrswrk !== "")
{
var labcstc = Number(hrswrk * hrrate);
alert("calc lab= " + labcstc);
var labcst = labcstc.toFixed(2);
var totcstc = Number(labcst + csmcst + msccst);
var totcst = totcstc.toFixed(2);
pui.set("T_LabCst.1",labcst);
pui.set("T_TotCst.1",totcst);
getObj("CostGrid").grid.refresh();
if (hrrate != hidcst)
{
applyProperty("T_OvrMsg", "visibility", "visible");
applyProperty("T_OvrLnk", "visibility", "visible");
}
else
{
applyProperty("T_OvrMsg", "visibility", "hidden");
applyProperty("T_OvrLnk", "visibility", "hidden");
}
}
}
}
- Glenn
- Profound Logic Staff Member
- Posts: 124
- Joined: Mon Apr 14, 2014 4:08 pm
- First Name: Glenn
- Last Name: Hopwood
- Company Name: Profound Logic Software
- State / Province: Ohio
- Country: United States
- Contact:
Re: onchange event
Patti,
Where did you put the updReqCost() function?
Glenn
Where did you put the updReqCost() function?
Glenn
-
- Experienced User
- Posts: 147
- Joined: Tue Jun 17, 2014 4:00 pm
- First Name: Patti
- Last Name: Bednarz
- Company Name: McGard
- State / Province: New York
- Country: United States
- Contact:
Re: onchange event
Hi Glenn,
Z:\profoundui\htdocs\profoundui\userdata\custom\js\engwkrq.js
The function is defined in the file in engwkrq.js
We have other functions in Z:\profoundui\htdocs\profoundui\userdata\custom\js that are working.
Patti
Z:\profoundui\htdocs\profoundui\userdata\custom\js\engwkrq.js
The function is defined in the file in engwkrq.js
We have other functions in Z:\profoundui\htdocs\profoundui\userdata\custom\js that are working.
Patti
Who is online
Users browsing this forum: No registered users and 2 guests