Design question about HTML select
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
Hello azbok, Saturday, October 20, 2001, 22:32:46, you wrote: [snip] ayc> 2) I can use ZPT TAL:condition sorta expressions to get the job done. ayc> My current solution is like this, but I don't like it at all: ayc> <SELECT NAME="a" TAL:define="ov options/optval"> ayc> <OPTION SELECTED TAL:condition="python:ov == 1">1</OPTION> ayc> <OPTION TAL:condition="python:ov != 1">1</OPTION> ayc> <OPTION SELECTED TAL:condition="python:ov == 2">2</OPTION> ayc> <OPTION TAL:condition="python:ov != 2">2</OPTION> ayc> <OPTION SELECTED TAL:condition="python:ov == 3">3</OPTION> ayc> <OPTION TAL:condition="python:ov != 3">3</OPTION> ayc> </SELECT> ayc> Is there a better more general solution? ayc> Thanks greatly for any suggestions you should be able to do something like: <untested> <select name="a" tal:define="ov options/optval;vals python:[1,2,3]"> <option tal:repeat="vals" tal:content="vals" tal:attributes="value vals;selected python:vals==ov">1</option> </select> </untested> good luck. :-) PS : there is also a separate ZPT-mailinglist where you will get replies top ZPT questions quicker. ( zpt@zope.org ) -- Geir Bækholt web-developer geirh@funcom.com funcom oslo | webdev-team
participants (2)
-
azbok@yahoo.com -
Geir Bækholt