Tutorial :generated template not rendering correctly



Question:

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.


Solution:1

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>  


Solution:2

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.


Solution:3

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »