Skip to main content

Calling Server Side Methods

Next, we surround the image with an anchor tag so that we can specify the functionality that we want to be invoked when a user clicks on the image. In this case, we do not want to display a new page, so we set the tag's href attribute to “.”.

When the user clicks on the image—in HTML parlance, when an “onClick” event occurs— we want some code to execute. We specify the code to execute using the onClick attribute of the <a> tag. Typically, this attribute contains JavaScript code that will run in the browser.

Here, though, we do something different: we use the

#server( ... )#

syntax to run code on the Caché server instead.

Note that we append the JavaScript code ";return false;" to the end of our attribute value to prevent the browser from attempting to follow the link defined by the href attribute. This is a standard JavaScript technique used when hyperlinks invoke functions.

<html> <body>
<csp:class encoded=1 super="%CSP.Page,Cinema.Utils">

<font> <b>Today's Show Times for #(Film.Title)#</b></font>

<table cellpadding=5> <tr> ... </tr>
<csp:while condition="Times.Next()">
    <td align="center">
    <a href=. onClick="#server(..AddShow(#(Times.GetData(1))#))#;return false;">
    <img src="Tickets.gif" width="130" height="39" border="0" 
    alt="Click to order tickets for this show">

</body> </html>
FeedbackOpens in a new tab