I have a hidden text box which is intended to pass a message from the RPG program to the JavaScript in my page. After my JavaScript gets the message, I want to programmatically clear that value so that my JavaScript doesn't react to it, again, until the next time the RPG program sends another message.
I'm using the following code but this doesn't seem to be doing it because I'm getting "ghost" reactions to the last message sent.
wob.displayMessageText = function(widgetId, msgSource, fadeDuration, position, event)
{
var messageText = get(msgSource.id); // get any message text
changeElementValue(msgSource.id, ""); // clear any message text
if (messageText <= " ") return; // if no message text, then exit
...snip...
}
Is there something else that needs to be done when the value of a widget is bound to an RPG variable?
Was this one of the 3 items we talked about yesterday? Sorry, I've had quite a busy day today, I'll be following up on your other items, too.
Here it looks like you are doing it the right way, the changeElementValue() call will set the text box to empty string. There must be something else going on. Have you debugged the script to see exactly what happens? I ran a quick test and found no problems. Calling 'changeElementValue()' with empty string does properly clear the widget in all respects:
1. Visually cleared in the browser.
2. get() call after returns empty string.
3. Empty string submits to the server.
So, something else must be doing on or some other factor is in play. Is this one of those cases you mentioned where you have different widget types bound to same field or anything like that?
Yes, this is one of three three things I mentioned as outstanding issues in Thursday's meeting. But, no, this is not a case of multiple widgets trying to use the same bound field. After the script runs and before submitting back to the server, I did a Ctrl-F9 of the screen and I can still see the message text showing in the bound RPG field. Is that normal?
Yes, it would be normal to see it still in the CTRL+F9 dump.
This is a capture of the last data that was received by the browser from the server. So it will have the data as at the time of screen render. It's not updated by the browser.
A good way to see what is submitted to the server if you want to check that is to use the browser's network request monitor. Try F12 tools in IE, Network tab.
You can see the POST request to program PUI0002110, which is the Genie server program.
I'm going to need some help, then, figuring out why I'm getting "ghost" reactions to the last message sent. Basically, even through the message is not being sent from the RPG program (confirmed by interactive debug on the RPG program), the get(msgSource.id) function in the JavaScript is returning the previous message text such that it displays on the screen again and again.
if (messageText <= " ") return; // if no message text, then exit
It's the <= " " part that baffles me. You are looking for strings that are less than blanks? Is an empty string less than a blank? Or more? How can you even quantify what an empty string will be?
I suspect that you know from prior experience than an empty string is less than a blank (why else would you code this) but to me it's quite puzzling. I would've found it much clearer if you trimmed the blanks from messageText and then compared against an empty string ("").
Am I right? OR, can you explain what that actually does when you set a string to "" and then compare it to <= " "?