8.6.2 Variable Values - Continued

If we select red, yellow, green and submit the form, we see this:

Netscape: Untitled

File Edit View Go Communicator
Location:
You picked these colors:
red yellow green
Pick some colors:

(Run this example.    Download the source.)

Entry function

The form's action URL was $url/show.html . That means that when we posted the form, it re-invoked the script ($url ), but Vortex started at the function show instead of the default main . Also, the output MIME type will be HTML (.html ), which is the default anyway. With this addition to the Vortex URL syntax, we can control where the script starts. This enables us to neatly split the script into a function which prints the form (main ) and one which services it (show ), without an "if" statement.

LOOP statement

The show function displays the colors we selected ($user_colors ) in a simple table with varying background colors. For each color, we need to show a table <TD> . So we use the <LOOP> statement in Vortex. This takes a variable, and executes the statements inside the block (up to </LOOP> ) once for each value of the variable. Inside the loop, the $user_colors variable is "dereferenced": only its currently-iterating value is visible. It is known as a loop variable .

For good measure, we print the form again so we can change our selections. We do this by calling the <main> function directly, which prints the form. Now another feature of <options> comes in handy - when we print the SELECT box, we want to highlight the options we've already selected. The second argument to <options> handles this: it's a list of values to highlight.

With just a few lines of code, we've handled some otherwise tedious tasks:

  • producing a <SELECT> box for a list of values

  • getting a multiple-value variable from a form

  • constructing a <TABLE> from those values

  • re-printing the form with proper pre-selected values
Back: Variable Values - Continued Next: LOOP
Copyright © 2024 Thunderstone Software LLC. All rights reserved.