javascript - IE : HTML select with huge options taking lot of time in loading -
my requirement load html drop down dynamically.
`
<html> <head> <script type="text/javascript"> function addselectbox() { var parentdiv = document.getelementbyid ("main"); var selectelement = document.createelement ("select"); (var i=0;i < 6000;i++) { var option = new option ("option --- " + i, "value" + i); selectelement.options[selectelement.options.length] = option; } parentdiv.appendchild (selectelement); } </script> </head> <body> <div id="main"> <input type="button" onclick="addselectbox()" name="clickme" value="add select box" /> </div> </body> </html>
`
in above code, on clicking of button, i'm creating dropdown options , adding div.
this takes less time (2-5 secs) in firefox , chrome. when run in internet explorer (11) it's taking more 20 seconds.
, while loading, page gets hanged blocks other operations also.
please find jsfiddle here
is there other way, can fast in ie.
or possible load in background , show loading message.
try instead. faster
function addselectbox(){ var parentdiv = document.getelementbyid ("main"); var selectelement = '<select>'; (var i=0;i < 6000;i++) { selectelement+= '<option value="'+i+'">---- ' + i+'</option>'; } selectelement += '</select>'; parentdiv.innerhtml+=selectelement; }
Comments
Post a Comment