[Zope] Design question about HTML select

azbok@yahoo.com azbok@yahoo.com
Sat, 20 Oct 2001 20:32:46 -0000


I have a simple select like so:

<SELECT NAME="a">
  <OPTION>1</OPTION>
  <OPTION>2</OPTION>
  <OPTION>3</OPTION>
</SELECT>

I'm using ZPT and based on an input variable - options/optval - want 
to have corresponding option selected.  If options/optval is 2, then 
the result I want is

<SELECT NAME="a">
  <OPTION>1</OPTION>
  <OPTION SELECTED>2</OPTION>
  <OPTION>3</OPTION>
</SELECT>

There's definatly 2 general methods.
1) I can use javascript to set the selected option which I don't want 
to use cause it will get messy.  This small example is part of a 
larger dynamic macro.

2) I can use ZPT TAL:condition sorta expressions to get the job done.

My current solution is like this, but I don't like it at all:

<SELECT NAME="a" TAL:define="ov options/optval">
  <OPTION SELECTED TAL:condition="python:ov == 1">1</OPTION>
  <OPTION TAL:condition="python:ov != 1">1</OPTION>
  <OPTION SELECTED TAL:condition="python:ov == 2">2</OPTION>
  <OPTION TAL:condition="python:ov != 2">2</OPTION>
  <OPTION SELECTED TAL:condition="python:ov == 3">3</OPTION>
  <OPTION TAL:condition="python:ov != 3">3</OPTION>
</SELECT>

Is there a better more general solution?
Thanks greatly for any suggestions