html - Javascript issue with IE11 -


my app working fine till ie9, stopped working when upgraded ie11. here sample html , js .

issue

in first run ie. on load works well. when select pda brand, second dropdown's options went blank.

in console there script error invalid calling object error on object clonedoptions.

function dynamicselect(id1, id2) {    //alert("everytime")    // browser , feature tests see if there enough w3c dom support      // obtain references both select boxes    var sel1 = document.getelementbyid(id1);    var sel2 = document.getelementbyid(id2);    // clone dynamic select box    var clone = sel2.clonenode(true);    // obtain references cloned options    var clonedoptions = clone.getelementsbytagname("option");    // onload init: call generic function display related options in dynamic select box    refreshdynamicselectoptions(sel1, sel2, clonedoptions);    // onchange of main select box: call generic function display related options in dynamic select box      sel1.onchange = function() {      refreshdynamicselectoptions(sel1, sel2, clonedoptions);    };  }    function refreshdynamicselectoptions(sel1, sel2, clonedoptions) {    while (sel2.options.length) {      sel2.remove(0);    }      //alert(sel1.options[sel1.selectedindex].value)      // create regular expression objects "select" , value of selected option of main select box class names    var pattern1 = /( |^)(select)( |$)/;    var pattern2 = new regexp("( |^)(" + sel1.options[sel1.selectedindex].value + ")( |$)");    // iterate through cloned options    //alert(clonedoptions.length);    (var = 0; < clonedoptions.length; i++) {      // if classname of cloned option either equals "select" or equals value of selected option of main select box        if (clonedoptions[i].classname.match(pattern1) || clonedoptions[i].classname.match(pattern2)) {        // clone option hidden option pool , append dynamic select box        //alert("did match")          sel2.appendchild(clonedoptions[i].clonenode(true));        //alert(sel2.options[1]);      }    }  }
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">  <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">    <head>    <title>dynamic selectbox example</title>    <script type="text/javascript" src="unobtrusivedynamicselect_ex5.js"></script>  </head>    <body>    <form action="#">      <div>        <select id="pda-brand">          <option value="select">select pda brand...</option>          <option value="dell">dell</option>          <option value="hp">hp</option>          <option value="palmone">palmone</option>        </select>        <select id="pda-type">          <option class="select" value="select">select pda type...</option>          <option class="dell" value="aximx30">axim x30</option>          <option class="dell" value="aximx50">axim x50</option>          <option class="hp" value="ipaqhx2750">ipaq hx2750</option>          <option class="hp" value="ipaqrx3715">ipaq rx3715</option>          <option class="hp" value="ipaqrz1710">ipaq rz1710</option>          <option class="palmone" value="tungstene2">tungsten e2</option>          <option class="palmone" value="tungstent5">tungsten t5</option>          <option class="palmone" value="zire72">zire 72</option>        </select>        <script type="text/javascript">          window.onload = function(e) {            dynamicselect("pda-brand", "pda-type");          }        </script>      </div>    </form>  </body>    </html>

line of issue

in below loc, clonedoptions getting invalid calling object error.

for (var = 0; < clonedoptions.length; i++) { 

i working in ie-11, please try yourself.

as per understanding issue is:

var clone = sel2.clonenode(true); var clonedoptions = clone.getelementsbytagname("option"); 

clonedoptions reference children of clone tag name option

  sel1.onchange = function() {     refreshdynamicselectoptions(sel1, sel2, clonedoptions);   }; 

in function there reference clonedoptions, no reference clone. clone garbagecollected ie couldn't find reason keep it. clonedoptions keeps reference collection doesn't exist.

you correct in own way, passing clone instead of clonedoptions , works me in ie11

function dynamicselect(id1, id2) {    //alert("everytime")    // browser , feature tests see if there enough w3c dom support      // obtain references both select boxes    var sel1 = document.getelementbyid(id1);    var sel2 = document.getelementbyid(id2);    // clone dynamic select box      // obtain references cloned options    var clone = sel2.clonenode(true);    // onload init: call generic function display related options in dynamic select box    refreshdynamicselectoptions(sel1, sel2, clone);    // onchange of main select box: call generic function display related options in dynamic select box      sel1.onchange = function() {      refreshdynamicselectoptions(sel1, sel2, clone);    };  }    function refreshdynamicselectoptions(sel1, sel2, clone) {    var clonedoptions = clone.getelementsbytagname("option");    while (sel2.options.length) {      sel2.remove(0);    }      //alert(sel1.options[sel1.selectedindex].value)      // create regular expression objects "select" , value of selected option of main select box class names    var pattern1 = /( |^)(select)( |$)/;    var pattern2 = new regexp("( |^)(" + sel1.options[sel1.selectedindex].value + ")( |$)");    // iterate through cloned options    //alert(clonedoptions.length);    (var = 0; < clonedoptions.length; i++) {      // if classname of cloned option either equals "select" or equals value of selected option of main select box        if (clonedoptions[i].classname.match(pattern1) || clonedoptions[i].classname.match(pattern2)) {        // clone option hidden option pool , append dynamic select box        //alert("did match")          sel2.appendchild(clonedoptions[i].clonenode(true));        //alert(sel2.options[1]);      }    }  }
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">  <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">    <head>    <title>dynamic selectbox example</title>    <script type="text/javascript" src="unobtrusivedynamicselect_ex5.js"></script>  </head>    <body>    <form action="#">      <div>        <select id="pda-brand">          <option value="select">select pda brand...</option>          <option value="dell">dell</option>          <option value="hp">hp</option>          <option value="palmone">palmone</option>        </select>        <select id="pda-type">          <option class="select" value="select">select pda type...</option>          <option class="dell" value="aximx30">axim x30</option>          <option class="dell" value="aximx50">axim x50</option>          <option class="hp" value="ipaqhx2750">ipaq hx2750</option>          <option class="hp" value="ipaqrx3715">ipaq rx3715</option>          <option class="hp" value="ipaqrz1710">ipaq rz1710</option>          <option class="palmone" value="tungstene2">tungsten e2</option>          <option class="palmone" value="tungstent5">tungsten t5</option>          <option class="palmone" value="zire72">zire 72</option>        </select>        <script type="text/javascript">          window.onload = function(e) {            dynamicselect("pda-brand", "pda-type");          }        </script>      </div>    </form>  </body>    </html>


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -