html - JavaScript: getElementById not working in IE8 -
i've simple javascript display selected option in span. works fine in browsers except ie8.
code -
<select onchange="searchdisplay(this.value)"> <option>kill</option> <option>bill</option> <option>by</option> <option>torentino</option> <option>is </option> <option>not </option> <option>good</option> <select> <span id="container"> <span>
script -
<script> function searchdisplay(val) { var div = document.getelementbyid('container'); div.innerhtml = val; } </script>
any solution this? thanks.
issue this.value
in ie8 change :-
<select onchange="searchdisplay(this.options[this.selectedindex].value)">
, shall work fine.
in current code
fix markup others said in comments.
<select onchange="searchdisplay(this.options[this.selectedindex].value)"> <option>kill</option> <option>bill</option> <option>by</option> <option>torentino</option> <option>is</option> <option>not</option> <option>good</option> </select> <span id="container"></span>
ideal way add value
attribute select options. , this.value
guaranteed work.
Comments
Post a Comment