Javascript – alfresco —- how to add event handler into surf template

alfresco, event-handling, javascript, surf
        <div class="yui-gd">            <div class="yui-u first"><label for="${args.htmlid}-addContent">${msg("label.HowToAddContent")}:</label></div>            <div class="yui-u">               <select id="addContent" name="addContent" onchange="dropdown(this)">                  <option value="1" selected="selected">${msg("label.generateFromDescription")}</option>                  <option value="2">${msg("label.uploadFile")}</option>               </select>                 </div>            </div><script type="text/javascript">//<![CDATA[       function dropdown(sel){              //if(document.getElementById("addContent").value == "1")            if(sel.value == "0"){               document.getElementById('desc').style.display = 'block'         }            else {            document.getElementById('desc').style.display = 'none'         }      }       //]]></script>

I write it because i want to add event handler into select box, it works well in firefox, but in IE it always throw null exception.
Even through i used attachEvent , it still can not work in IE.
If i use document.getElementById("addContent") in above, it will always throw null exception!
But all these things work well in Firefox!

Can someone tell me why ?
Thanks in advance !

Best Solution

Which IE version are you using?If it's an old version, try to get the selected value through the options:

var selectedValue = sel.options[sel.selectedIndex].value;