html - javascript function crashes my browser -


i coded simple program take 2 textareas , combine every single line of 1 textarea lines in second textarea , browser crushes after 6000 lines. resul of check needs 100,000 lines.

this javascript code:

function go() {     var lines1 = $('#text1').val().split(/\n/);     var lines2 = $('#text2').val().split(/\n/);     var textarea1 = [];     var textarea2 = [];     var textarea3 = [];     (var = 0; < lines1.length; i++) {         if (/\s/.test(lines1[i])) {             textarea1.push($.trim(lines1[i]));         }     }     (var j = 0; j < lines2.length; j++) {         if (/\s/.test(lines2[j])) {             textarea2.push($.trim(lines2[j]));         }     }     (var k = 0; k < lines1.length; k++) {         (var q = 0; q < lines2.length; q++) {             textarea3.push($.trim(lines1[k] + ' ' + lines2[q]));             var msg = textarea3.join("\n");             document.getelementbyid('text3').value = msg;         }     } } 

this html:

<textarea name="textarea" id="text1"></textarea> <textarea name="textarea" id="text2"></textarea> <input type="button" value="go!" onclick="go()"> <br /> <textarea name="textarea" id="text3"></textarea> 

the problem code

    (var k=0; k < lines1.length ; k++) {         (var q=0; q < lines2.length ; q++) {             textarea3.push($.trim(lines1[k] + ' ' + lines2[q]));             var msg = textarea3.join("\n");             document.getelementbyid('text3').value = msg;         }     } 

if there 1k lines in textarea1 , 1k in testarea2 modify dom (by changing value of textarea3) 1m times insane. instead of updating dom every time try outside loop.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -