Skip to main content

Selecting a List Item

We also need to make sure that the current number of tickets is selected in the list. In HTML, we select a list item by specifying <option selected>.

It's easy to do this by using a <csp:if> tag to test whether the loop counter, i, is equal to the AdultTickets value from the object.

—Order.csp—
Order.csp
<html> <head></head>
<body>
<csp:class super="%CSP.Page,Cinema.Utils">
<csp:if condition='$D(%session.Data("Order"))'>
    <img src="YourTicketOrder.gif"><br>
    <script language="cache" runat="server">
        // Open Order object for display
        Set ord = ##class(Cinema.TicketOrder).%OpenId(%session.Data("Order"))
    </script>
    <csp:loop counter="num" from=1 to=#( ord.Items.Count() )#>
        <script language="cache" runat="server">
            Set itm = ord.Items.GetAt(num)
        </script>
        For the #($ZT(itm.Show.StartTime,4))#
        showing of #(itm.Show.Film.Title)#
        at #(itm.Show.Theater.TheaterName)#
        <br><br>
        <select name="AdultTickets">
            <csp:loop counter="i" from=0 to=9>
                <csp:if condition='itm.AdultTickets = i'>
                    <option selected>
                <csp:else>
                    <option>
                </csp:if>
                #(i)#
                </option>
            </csp:loop>
        </select>Adult Tickets<br>
    </csp:loop>
</csp:if>
</body> </html>
FeedbackOpens in a new tab