[Zope] dynamic radio buttons

Jonathan Hobbs toolkit at magma.ca
Sat Oct 2 14:45:52 EDT 2004


From: "garry saddington" <garry at joydiv.fsnet.co.uk>
> Is there any way to use radio buttons generated dynamically as a result of
a
> ZSQL method. Each iteration needs to have a different  name if they are to
be
> treated as a separate group. The problem is compounded by the fact that I
> must write the user's choices to a database. Here is the code I have so
far:
>
> <form action=formhandlerinputresults>
> <table border=1>
> <tr><th>Name</th><th>Exam Grade</th><th>Term Grade</th></tr>
> <dtml-in getclassmembers>
> <input type=hidden name=result.studentid:records value=<dtml-var
studentid>>
> <input type=hidden name=result.classid:records value=<dtml-var teacherid>>
> <tr><td><dtml-var firstname> <dtml-var surname></td>
> <td><input type =radio name=result.mark:records  value="A">A&nbsp;
> <input type =radio name=result.mark:records value="B">B&nbsp;
> <input type =radio name=result.mark:records value="C">C&nbsp;
> <input type =radio name=result.mark:records value="D">D&nbsp;
> <input type =radio name=result.mark:records value="E">E&nbsp;
> <input type =radio name=result.mark:records value="F">F&nbsp;
> </td><td><input type =radio name=result.termmark:records
value="A">A&nbsp;
> <input type =radio name=result.termmark:records value="B">B&nbsp;
> <input type =radio name=result.termmark:records value="C">C&nbsp;
> <input type =radio name=result.termmark:records value="D">D&nbsp;
> <input type =radio name=result.termmark:records value="E">E&nbsp;
> <input type =radio name=result.termmark:records value="F">F&nbsp;
> </td></tr></dtml-in></table>
> <br><br>
>
> <input type=submit value="Enter Results">

I am not quite sure what you are looking for, but you want to have a
different radio button 'name' for each iteration thru the dtml-in loop you
could use the 'sequence-index' or 'sequence-number' loop variables.

eg.

<input type =radio name=<dtml-var sequence-index>:records value="A">B&nbsp;
<input type =radio name=<dtml-var sequence-index>:records value="B">B&nbsp;
<input type =radio name=<dtml-var sequence-index>:records value="C">B&nbsp;
<input type =radio name=<dtml-var sequence-index>:records value="D">B&nbsp;
<input type =radio name=<dtml-var sequence-index>:records value="E">B&nbsp;
<input type =radio name=<dtml-var sequence-index>:records value="F">B&nbsp;


This will give you a set of radio buttons (labelled 0-n, where n is the
number of dtml-in loop iterations - 1) that have the same name for any given
loop iteration, but will change from one loop iteration to the next.
(sequence-number counts from 1 instead of from 0).

HTH

Jonathan







More information about the Zope mailing list