Focal Point
[SOLVED] Dynamically change the text in an edit box in Maintain

This topic can be found at:
http://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/7001064662

January 16, 2008, 04:05 PM
brjohnson
[SOLVED] Dynamically change the text in an edit box in Maintain
Hi,

I'm a noobie to Maintain so I apologize if this is a simple question. I was wondering how to dynamically change the text in an edit box. I have a form with three fields on it. I want the third box to automatically contain the product of the first two fields(hours * rate = pay). I want pay to be a read only field that only contains data when a change is made to hours or rate.

Any assistance would be appreciated.

Thanks

This message has been edited. Last edited by: brjohnson,


Bryan Johnson
WebFOCUS 7.7.03
Maintain
Win 7
Excel, PDF, HTML
January 16, 2008, 04:33 PM
Alan B
This should be simple. Remember that when maintain is displaying in the browser you are dealing with HTML, so to change the page use javascript. You could achieve this in maintain itself, but that is overkill.

If you have 3 edit boxes with ids' of hours, rate and pay, then on the event handler on hours and rate create an event handler for an onchange event calling javascript, in there simply use code like:
document.getElementById("pay").value = document.getElementById("hours").value * document.getElementById("rate").value; 


Hope this does what is required.


Alan.
WF 7.705/8.007
January 16, 2008, 04:58 PM
brjohnson
Thanks Alan I'm not sure why I didn't think of that, but that worked great.


Bryan Johnson
WebFOCUS 7.7.03
Maintain
Win 7
Excel, PDF, HTML
January 17, 2008, 09:08 AM
Maintain Wizard
Please allow me to add in an additional solution. The JavaScript solution is excellent, but if the form redisplays, that value will disappear. While this way involves a return to the server, it is the way to do computes in Maintain.

I will assume that you have:

COMPUTE PAY/D7.2;
HOURS/D7.2;
RATE/D7.2;

And you have placed those fields on the screen. When the user enters Hours and Rate, you can either press a button or use an On_Change trigger for the rate field. You would have a Maintain case containing:

CASE GETPAY
COMPUTE PAY = HOURS * RATE;
ENDCASE

When you trigger that case, Pay will be set and displayed.

Mark
January 17, 2008, 01:02 PM
Dave Ayers
Mark,

Can the two approaches be combined ?

That is, have the three fields bound to the three form objects (edit boxes) and use a Javascript blur event handler to calculate the Rate box value, which would then be returned to Maintain when the page is submitted.

What I am not sure of is if the Rate edit box is set to read-only at design time, will Javascript be able to change the vale at runtime without toggling that property ?

Dave


Regards,
Dave

http://www.daveayers.com

WebFocus/Maintain 7.6.4-8
on Win2000 and 2003 Server
January 17, 2008, 01:29 PM
Alan B
Dave

I'm sure Mark will respond as well. JS and bound objects can be combined as you describe.

The readonly context is for the user and does not affect the JS capability to update it.


Alan.
WF 7.705/8.007
January 17, 2008, 01:34 PM
Maintain Wizard
As Alan points out, data inserted into a field via JavaScript will certainly be sent back to the server. However, if the form gets refreshed, value and attributes set only by JavaScript may get reset.

Mark