views:

91

answers:

3

So I have this code in a google app engine template:

<select name='voter'>

{% for voter in allowed_voters %}

    <option {% ifequal voter last_voter %}selected="yes" {% endifequal %} 
    value='{{voter}}'>{{voter}}</option>

{% endfor %}

</select>

The page doesn't render with the correct person selected, defaulting instead to the 1st option. Viewing the source shows me that the generated html has put the selected attribute in the correct place, so I can't figure out why this isn't working.

A: 

try just the token 'selected' rather than selected="yes"

bskinner
+4  A: 

option's select attribute is a boolean attribute.

Try one of the following:

<option {% ifequal voter last_voter %}selected="selected" {% endifequal %} 
value='{{voter}}'>{{voter}}</option>


<option {% ifequal voter last_voter %}selected {% endifequal %} 
value='{{voter}}'>{{voter}}</option>
strager
Thanks for the help, it turns out the problem was elsewhere though.
wodemoneke
+1  A: 

The syntax of boolean attributes is different in HTML and XHTML. Apparently you're outputting HTML, and need to use

<option ... selected ...>

In XHTML you would use

<option ... selected="selected" ...>

It's unfortunate that we have the whole HTML/XHTML and MIME types mess with horribly non-standards-compliant browsers. You just have to know this stuff to be sure you're spitting out pages that render correctly on most browsers.

akaihola