[Zope-dev] Selecting an option from a drop-down list at run-time with DTML

Richard McKinley richard_mckinley@hotmail.com
Wed, 08 May 2002 11:08:54 +0000


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>

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&#8722;if expr="<dtml-var "RESEARCH_PURPOSE"> == <dtml-var 
"PURPOSE">">
          SELECTED
      </dtml&#8722;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..

Many thanks,
Richard

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com