GrazrScript Tutorial

Field types

GrazrScript supports all of the available XHTML form field types, but we've only tried examples of input fields and listboxes. Let's look at some of the other types of form fields that are available.

Checkbox

A checkbox field is set equal to its value attribute if the box is checked, or blank if it is left unchecked. If you use the same field name with multiple checkboxes, the field is set equal to all of the checked values separated by spaces. This becomes a convenient way for a user to select from one or more options.

http://docs.grazr.com/script/tutorial/checkbox.xml
<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0" xmlns:grazr="http://docs.grazr.com/script/spec/1.0">
<head>
<title>Boston Sports Search</title>
</head>
<body>
<grazr:form name="sportsform">
Pick your favorite teams:<br />
<input type="checkbox" name="teamlist" value="red sox" checked="checked" />Red Sox<br />
<input type="checkbox" name="teamlist" value="bruins" />Bruins<br />
<input type="checkbox" name="teamlist" value="celtics" />Celtics<br />
<input type="checkbox" name="teamlist" value="patriots" />Patriots<br />
<input type="submit" value="Search" /><br />
</grazr:form>

<grazr:formtemplate name="sportsform"
file="http://news.google.com/news?q=sports+%teamlist%&amp;output=rss" />

<grazr:formresult text="Boston sports news:" name="sportsform" />

</body>
</opml>


Multiple-select listbox

Another method of getting multiple values from a form is with a listbox that has been set to a multiple select format. The user can select more than one value by holding down the control key while clicking. The substitution value received from the form is a list of the items selected separated by spaces.

http://docs.grazr.com/script/tutorial/multiple.xml
<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0" xmlns:grazr="http://docs.grazr.com/script/spec/1.0">
<head>
<title>Recipe Search</title>
</head>
<body>
<grazr:form name="recipeform">
Recipe Search: <br />
(Ctrl-click to select multiple ingredients)<br />
<select name="ingredients" size="5" multiple="multiple">
<option value="mushroom">mushroom</option>
<option value="sausage">sausage</option>
<option value="rice">rice</option>
<option value="beans">beans</option>
<option value="tomato">tomato</option>
</select><p />
<input type="submit" value="Cook These Ingredients" /><br />
</grazr:form>

<grazr:formtemplate name="recipeform">
<outline text="Ingredients: %ingredients%" type="rss"
xmlUrl="http://www.google.com/base/search?a_n0=recipes&amp;q=%ingredients%&amp;output=rss" />
</grazr:formtemplate>

<grazr:formresult text="Recipes:" name="recipeform" />

</body>
</opml>


Radiobuttons

Radiobuttons offer a mutually exclusive set of options. Only one of the possible values can be selected.

http://docs.grazr.com/script/tutorial/radio.xml
<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0" xmlns:grazr="http://docs.grazr.com/script/spec/1.0">
<head>
<title>Video Search</title>
</head>
<body>
<grazr:form name="videoform">
Video Search:<br />
<input type="radio" name="query" value="Natalie Portman" checked="checked" />Natalie Portman<br />
<input type="radio" name="query" value="Star Trek" />Star Trek<br />
<input type="radio" name="query" value="Star Wars" />Star Wars<br />
<input type="submit" value="View" /><br />
</grazr:form>

<grazr:formtemplate name="videoform"
file="http://www.youtube.com/rss/tag/%query%.rss" />

<grazr:formresult text="YouTube Videos:" name="videoform" />

</body>
</opml>

Field validationProcedural programming