I am using a drop down for dynamically changing content on a page. It works but is throwing a js error in Chrome ONLY. What Chrome recommends I don't know how to implement. Site is built in ExpressionEngine 2.8.1.
ERROR MESSAGE IN CHROME
Uncaught TypeError: Cannot set property 'onchange' of null functions.js:65
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
MY JS Code
document.getElementById("drop").onchange = function() {
if (this.selectedIndex!==0) {
window.location.href = this.value;
}
};
MY HTML Code
<form method="post" action="{path='locations/index'}" class="drop">
<select id="drop">
<option>Select a Location:</option>
{exp:channel:entries channel="locations" category="not 3" orderby="title" sort="asc" dynamic="no"}
<option value="{site_url}index.php/locations/{url_title}">{title}</option>
{/exp:channel:entries}
</select>
</form>
$(document).ready()
maybe? If the code really works in other browsers, your template probably breaks in Chrome. You could check theinnerHTML
of theform
just before trying to set the event handler toselect
. Can you see the select tag and its id? – Algonquian