[Zope] Selecting an option in a drop-down list in DTML
hans
hans@beehive.de
Wed, 08 May 2002 13:24:08 +0100
Richard McKinley wrote:
> Hi,
>
> I have a drop-down list which is dynamically populated from a database
> lookup table using the <dtml-in> structure to iterate through the list of
> rows and add an <OPTION> to the drop-down for each row in the table.
>
> like so:
>
> <select name="Purpose">
> <dtml-in sqlLookupResearchPurpose>
>
> <option value="<dtml-var "RESEARCH_PURPOSE">"> <dtml- var
> "RESEARCH_PURPOSE"> </option>
>
> </dtml-in>
> </select>
>
> I want to be able to add the SELECTED HTML attribute to a specific option
> which is determined only at runtime. Basically if the current value of
> research_purpose field equals the value of the purpose variable I want to
> insert the select attribute at this point.
>
> <dtml-if expr="<dtml-var "RESEARCH_PURPOSE"> == <dtml-var "PURPOSE">">
> SELECTED
> </dtml-if>
>
jou cant nest <dtml-...> tags
>
> However, I get a syntax error. How do you usually test the condition when 2
> variable are equal?
>
> Putting the code together:
>
> <select name="Purpose">
> <dtml-in sqlLookupResearchPurpose>
> <option value="<dtml-var "RESEARCH_PURPOSE">"
>
> <dtml−if expr="<dtml-var "RESEARCH_PURPOSE"> == <dtml-var
> "PURPOSE">">
> SELECTED
> </dtml−if>
>
> > <dtml-var "RESEARCH_PURPOSE"> </option>
> </dtml-in>
>
> </select>
>
> If anyone could show me how this is normally done or point me in the
> direction of any tutorials/how-tos etc. it would be appreciated..
<select name="Purpose">
<dtml-let res=sqlLookupResearchPurpose>
<dtml-in res>
<option value="<dtml-var "RESEARCH_PURPOSE">"
<dtml-if "RESEARCH_PURPOSE==PURPOSE">SELECTED</dtml-if>
><dtml-var "RESEARCH_PURPOSE">
</option>
</dtml-in res>
</dtml-let res>
</select>
--
-------------------------------------------------------------
Who's got only a hammer sees the world as a nail
hans augustin (software developer) hans@beehive.de
beehive elektronische medien GmbH http://www.beehive.de
phone: +49 30 847-82 0 fax: +49 30 847-82 299