[ZPT] option selected?

cccurvey scurvey at nwaf.com
Mon Jan 5 14:15:58 EST 2004


Ack!  I'm both confused and off-topic!  I'm trying to make sure that
the select box that's in the form reflects the state of the record
that was retrieved from the database (and I'm using the SimpleTAL
package from owlfish.com to do this outside of Zope).  

    Category:
    <select name="categoryId">
        <option tal:repeat="category categoryList"
	        tal:attributes="selected 
                    python:category['categoryId']==case.categoryId; 
                    value category/categoryId"
		tal:content="category/categoryName">
        </option>
    </select>

This all works well and gives me something like

<select name="categoryId">
    <option value="1" selected="false">Foo</option>
    <option value="2" selected="true">Bar</option>
    <option value="3" selected="false">Snafu</option>
</select>

But the problem is that the browsers seem to be always selecting the
last item in the list.  It appears that they pick the last option with
a "selected" attribute, regardless of what the value is.

How do I work around this to only put the "selected" tag on the option
which is actually selected?

If I'm too far off-topic, let me know and I'll be quiet.

Thanks!




More information about the ZPT mailing list