33. Exercise 8

It’s time to get (mildly) interactive.

Starting with the results of the previous exercise, add a template that will fire when the user selects a different value for the number of servings.

Detect the change event on the select element.

In future exercises, we’ll look at the larger problem of actually updating the recipe.

For this exercise, just do something really simple to demonstrate that you’ve captured the event. For example:

(If you choose to use xsl:message, remember that you’ll have to look at the browser console window to see the output!)

The event-handling template should look like this:

<xsl:template match="select" mode="ixsl:onchange">
  ...
</xsl:template>

(We’ve provided an alternate answer “8b” that uses a couple of extra extension functions to pop up a browser alert box. The functions are described in the appendices.)

Once again, we’ll jump right into the next exercise, so feel free to peek ahead after you’ve finished this exercise.