+ Start a Discussion

Writing conditionals in HTML with Visualforce

I've been experiencing some strange behavior.


This code in a Visualforce page:



	          <option value="{!v.so.value}" {!IF(v.selected == TRUE,'selected="selected"','')}>{!v.so.label}, {!IF(v.selected == TRUE,'selected','not selected')}</option>



Results in this HTML:



           <option selected="selected" value="Option 5" >Option 5, not selected</option>


Note two very bizarre things:


(1) The order of the elements in the option (selected and value) is reversed.



(2) It always renders the if true condition even when the condition is false (this happens only inside the element tag, not for HTML).



Ideas as to why either of these is happening?




Re: 1 - I've seen other XML-based UI markup tools that do something similar with XML element attributes... I imagine that technically the order of the "option" attributes shouldn't matter because it's still valid, parse-able XML, so maybe the ordering of the attributes is not considered important by the VF HTML renderer also...