Page 1 of 1

Update field via JS before submitting data

Posted: Wed Feb 25, 2015 9:04 am
by Steve Bone
I want to update a field via Javascript in my program just before submitting the information to the RPG program.
The updated field should contain the ID of the display field that last received input.

The problem is, when I use the onsubmit() event of the Record of the Displayfile, the javascript seems to be activated after the data was submitted. So with the next exfmt of my record, the field is empty again.
So instead of the onsubmit() event of the record, I use the onfocus() event of every field in the display now.
It works, but I do not like that I have to add this one line JS to everything in my Display.

Is there a way I can update the field with the ID of the Display field that currently has the focus without adding the JS to every onfocus() event on the screen?

Re: Update field via JS before submitting data

Posted: Wed Feb 25, 2015 10:19 am
by Alex
The event can be specified as a function name only. If used in this way, a response object containing all the values is passed to the specified function. The function can interrogate and even change the response values. The names in this object are stored as "FORMAT.FIELDNAME", where the format and the field name are both capitalized. So, in your external JavaScript file, you can create a function like this:

Code: Select all

function updateResponse(response) {
  response["MYSCREEN.MYDATA"] = "some information";
}
The onsubmit event would only have the function name:

Code: Select all

onsubmit: updateResponse