Click here to Skip to main content
16,015,900 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a java script function as:

XML
<script type="text/javascript" >
 var FileTypeGroupValues1 = '<%= FileTypeGroupValues.ClientID %>';
            var GroupArr;
            var VariableRecord;
            FillFileTypeArray();
            function FillFileTypeArray() {

                var strFileTypeGroup = document.getElementById(FileTypeGroupValues1).value;
                var IE = document.all ? true : false;
                if (strFileTypeGroup != "") {
                    if (IE) {
                        window.execScript(strFileTypeGroup);
                    }
                    else {

                            GroupArr = eval(strFileTypeGroup);

                        }
                    }
                }
                alert(GroupArr.length );
            }
</script>


here you can put value of strFileTypeGroup="var GroupArr = new Array();GroupArr[0] = '19~3';GroupArr[1] = '19~4';GroupArr[2] = '20~5';GroupArr[3] = '20~6';GroupArr[4] = '18~8';GroupArr[5] = '20~9';GroupArr[6] = '19~10';GroupArr[7] = '19~11';GroupArr[8] = '17~12';GroupArr[9] = '19~13';GroupArr[10] = '20~14';GroupArr[11] = '19~15';GroupArr[12] = '18~16';GroupArr[13] = '18~17';GroupArr[14] = '17~21';GroupArr[15] = '20~22';GroupArr[16] = '20~16';GroupArr[17] = '8~28';GroupArr[18] = '15~28';GroupArr[19] = '0~31';GroupArr[20] = '0~32';GroupArr[21] = '0~33';GroupArr[22] = '19~23';GroupArr[23] = '0~41';GroupArr[24] = '1~2';GroupArr[25] = '0~42';GroupArr[26] = '2~5';GroupArr[27] = '6~1';GroupArr[28] = '4~1';GroupArr[29] = '0~43';GroupArr[30] = '0~44';";

When I run this function in IE7,8,9,10 and FireFox it gives GroupArr.length=31
but it gives wrong results in IE 11 and chrome.

Please help, I am badly stuck in this problem.

Thanks & Regards
Mohammad Wasif
Posted
Comments
Bernhard Hiller 7-Jan-14 2:50am    
"gives wrong results in IE 11 and chrome"
OK, you told us that you expect "31", but you did not tell us what you get in IE11 and chrome.

1 solution

JavaScript's eval function will return the result of the last command executed, in your case it is '0~44'.
So length will 4 - and it is true for all browsers. I run it on IE9, Opera, Firefox, Chrome, IE 11 and Safari - all returns 4!
If you want to create some dynamic array try this:
JavaScript
var cmd = "['19~3','19~4','20~5','20~6','18~8','20~9','19~10','19~11','17~12','19~13','20~14','19~15','18~16','18~17','17~21','20~22','20~16','8~28','15~28','0~31','0~32','0~33','19~23','0~41','1~2','0~42','2~5','6~1','4~1','0~43','0~44']";

var GroupArr = eval(cmd);

alert(GroupArr.length);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900