ttomasko
Programmer
- Aug 6, 2008
- 28
Hello,
I often have to display the elements of an array in an alert box (probably not a good thing on the web but this is for the InDesign program).
When there are many elements this creates an alert box that is so long that one cannot find the bottom in order to dismiss the alert.
Below is a script that allows only for displaying the first 10 elements. I am just wondering if there is a shorter or better way to write this.
Thanks,
Tom
I often have to display the elements of an array in an alert box (probably not a good thing on the web but this is for the InDesign program).
When there are many elements this creates an alert box that is so long that one cannot find the bottom in order to dismiss the alert.
Below is a script that allows only for displaying the first 10 elements. I am just wondering if there is a shorter or better way to write this.
Thanks,
Tom
Code:
//var aa = [1,2,3,4,5,6];
var aa = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30];
var alertText = "";
var cutOffAlert = "";
if(aa.length <= 9){
lessThan9();
}//end if
if(aa.length > 9){
moreThan9();
}//end if
alert(alertText);
//****functions*******
function lessThan9(){
for(var i = 0; aa.length > i; i++){
alertText += "Page "+aa[i]+"\r\r\r";
}//end for i
return alertText;
}//end function lessThan9
function moreThan9(){
for(var j = 0; aa.length > j; j++){
cutOffAlert += "Page "+aa[j]+"\r\r\r";
if(j > 8){
break;
}//end if
}//end for
alertText = "Help! This is too long to see the OK button on the bottom!\r\r"+cutOffAlert+"There are "+(aa.length-10)+" more elements. Click Yes (if this were a confirm) to get a .txt document of all of them."
return alertText;
}//end function moreThan9