OnReturn Functions
You will have noticed on the previous page that the variables returned by
MapServer are not automatically put in the text boxes: you have to
click a button. Is there a way to do this automatically? Well, look in
how this button is defined:
<input type=button value="Get Variables" onclick=getVars()>
The button has an "onclick function" defined on it, a function that is
executed when the
button is clicked. MapClient has many such "event functions" or
"callback functions". One of them is the win method "setExecOnReturn()".
This binds a user defined function to a window: whenever a webserver has
finished putting
anything in the window, the user defined function is automatically executed.
The new HTML page
is almost identical to the previous one. The "Get Variables"
button has disappeared, and its onclick function has been assigned to
the window's onReturn event:
w.setExecOnReturn(getVars)
Now "getVars()" is executed whenever MapServer has
finished putting a new map in the window
.
Note that the getVars() function itself hasn't changed at all. You can imagine
an onReturn function as a button that is automatically clicked when a
WebServer has interacted with a window.
Even when a new map is produced after resizing,
due to the
"execOnResize()" function, the "execOnReturn()" function will be executed
.
OnReturn function are really the heart of MapClient. All interaction is
done via hidden variables, and on return the results are transferred from
these variables to the actual browser location. No layouting is ever done
at the server; the server only processes information, and the browser
is completely responsible for displaying it. Browser and server
only communicate by exchanging hidden variables. This makes for much clearer
programming logic; it is also faster, because the browser
layout does not have to be updated at every server request.