Selecting an option in a drop-down list in DTML
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−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.. Many thanks, Richard _________________________________________________________________ Join the worlds largest e-mail service with MSN Hotmail. http://www.hotmail.com
on or about, Wednesday, May 08, 2002, we have reason to believe that Richard McKinley wrote something along the lines of : RM> I want to be able to add the SELECTED HTML attribute to a specific option RM> which is determined only at runtime. Basically if the current value of RM> research_purpose field equals the value of the purpose variable I want to RM> insert the select attribute at this point. [snip] RM> However, I get a syntax error. How do you usually test the condition when 2 RM> variable are equal? <dtml-if expr="RESEARCH_PURPOSE == PURPOSE"> selected=selected </dtml-if> :-) stuff inside quotes is the same as inside expr="" , meaning a python-expression.. You cannot use DTML in python expressions. -- Geir Bækholt web-developer geirh@funcom.com funcom oslo | webdev-team
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
participants (3)
-
Geir B�kholt -
hans -
Richard McKinley