tags:

views:

55

answers:

2

All,

In Template condition check,whats wrong with the following code,

selected_id and selected_sub are equal to 5 but still ifequal loop is not working..

<tr><td><p>Subjects:</td>
<td>
<select id="subjects" name="subjects" multiple="multiple">
{% for subject in subjects %}
<option value="{{subject.id}}" {% for selected_id in selected_sub %}{% ifequal subject.id selected_id %} {{ selected }} {% endifequal %} {% endfor %} >{{subject.subject}}</option>
{% endfor %} 
</select>
</p></td></tr>

Thanks..........

+1  A: 

If, as you say, selected_id and selected_sub are equal to 5 then

for selected_id in selected_sub

will not work, since 5 is not iterable.

jellybean
No this is sumthing like for a in 5; printa;
Hulk
Which doesn't work. Try it at a Python prompt. 5 is not iterable.
Daniel Roseman
+1  A: 

Ok, sorry. What is the output you get?

selected should have the value 'selected="selected"'.

Change to {% with selected as 'selected="selected"' %} and try again.

Felix Kling
This is a multiple select box.So the purpose is that if any exception in views the same values should be restored for consistency.And for loop i.e,selected_sub contaiing the array of selected values......
Hulk
K thanks................
Hulk