0

JavaScript not working on IE8 -getting type mismatch on this particular line:

from_s.add(temp, from_s.options[0]);

I have run this search/display code on Firefox and higher version of ie's and it worked perfectly fine. I just don't get it, =(( i really really need this one to work, I hope someone out there could help me =(

Here is my code that searches for a keyword and puts it on top of the list:

JavaScript:

<script type="text/javascript">
  function searchstudent(){
    var searchvalue= document.getElementById('search').value;
    var from_s = document.getElementById('students-out');
    for (var i=0;i<from_s.options.length-1;i++){
      var st = from_s.options[i].text;
      if(st.search(searchvalue)>-1){
        var temp = from_s.options[i];
        from_s.add(temp, from_s.options[0]);
      }
   }
 }

and the form:

<form id="search2">
  <input type="text" id="search" onkeyup="searchstudent()" placeholder="Enter Keyword here.. ." /><br/><br/><br/>
  <select name="users-out" id="students-out" multiple="multiple" size="10" onchange="location = this.options[this.selectedIndex].value;">
    <option value="n.html" title="ppp">ppp</option>
    <option value="n.html" title="ppp">yyy</option>
    <option value="g.html" title="qwe">qwe</option>
    <option value="32" title="bond desk">bond desk</option>
    <option value="32" title="qqq">qqq</option>
    <option value="26" title="     ">     </option>
  </select>
</form>

1 Answer 1

1

It looks like add() does not exist on HTMLSelectElement in IE8.

Instead you could probably use the much more consistent and standardized insertBefore() DOM Node method.

from_s.insertBefore(temp, from_s.options[0]);

Or appendChild() if you want it at the end.

See also: JavaScript Error in add method using IE8

1
  • IE 7 and 8 support the add method on select elements.
    – RobG
    Jun 19, 2014 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.