[JS CS4] Sorting linked dropdownlists alphabetically problem
Skempy Apr 1, 2010 6:42 AMHi,
I have built a simple dialog script that looks up and displays data from a CSV file. There are three drop down lists with the first two being linked to each other so the selection in the second changes if the selection in the first changes.
I am quite pleased with this especially as I only need update the CSV file to have the dropdown list automatically populated. Someone I have shown this to has pointed out that the second dropdown is not sorted alphabetically.
My problem is that I can only have either one or the other list displayed aphabetically.
Here is the code so far, a lot of which I got from the kind contibutors of this forum. I have added a link to the script and CSV file.
var colWidthValue = "100mm"
var firstLine = getHeadings();
firstLine.shift()
firstLine.shift()
var colWidths = firstLine;
var myPubCodeList = getCodes(0)
var myTitlesList = getCodes(1)
var w = new Window("dialog", "Publication Information Lookup");
w.orientation = "row";
w.addList = new Array();
// 1st Drop Down
w.textPubCode = w.add('statictext', undefined, 'Pub Code:');
w.pubCodes = w.add('dropdownlist',undefined,myPubCodeList);
w.pubCodes.selection = w.pubCodes.items[0];
// 2nd Drop Down
w.textTitle = w.add('statictext', undefined, 'Title:');
w.Titles = w.add('dropdownlist',undefined,myTitlesList);
w.Titles.selection = w.Titles.items[0];
w.Titles.onChange = function() {
w.pubCodes.selection = w.Titles.selection.index;
}
// 3rd Drop Down
w.textCols = w.add('statictext', undefined, 'Data:');
w.colNum = w.add('dropdownlist',undefined,colWidths);
w.colNum.selection = w.colNum.items[0];
w.group = w.add( "group" );
w.pubCodes.onChange = function() {
code = w.pubCodes.selection.text
cols = w.colNum.selection.index
w.Titles.selection = w.pubCodes.selection.index;
if ( this.window.addList.length > 0 ) {
this.window.group.remove( this.window.addList.pop() );
this.window.layout.layout( true );
}
this.window.addList.push( w.group.add( "statictext", undefined, getWidth(code,cols+2)) );
this.window.layout.layout( true );
}
w.colNum.onChange = function() {
code = w.pubCodes.selection.text
cols = w.colNum.selection.index
if ( this.window.addList.length > 0 ) {
this.window.group.remove( this.window.addList.pop() );
this.window.layout.layout( true );
}
this.window.addList.push( w.group.add( "statictext", undefined, getWidth(code,cols+2)) );
this.window.layout.layout( true );
}
w.show();
function getWidth(myPubCode,myCols) {
mySizeFile = File("C:/size_lookup.csv");
mySizeFile.open("r", undefined, undefined);
do{
myLine = mySizeFile.readln();
myPubArray = myLine.split(",");
//alert(myPubArray[0] + " | " + myPubCode);
if(myPubArray[0] == myPubCode) {
return myPubArray[myCols];
break;
}
} while(mySizeFile.eof == false);
mySizeFile.close();
}
function getCodes(c) {
var myArray = []
mySizeFile = File("C:/size_lookup.csv");
mySizeFile.open("r", undefined, undefined);
do{
myLine = mySizeFile.readln();
mytempArray = myLine.split(",");
myArray.push(mytempArray[c]);
} while(mySizeFile.eof == false);
mySizeFile.close();
return myArray
}
function getHeadings() {
var myArray = []
mySizeFile = File("C:/size_lookup.csv");
mySizeFile.open("r", undefined, undefined);
myLine = mySizeFile.readln();
myArray = myLine.split(",");
return myArray
}
I know my scripting is probably clumsy and long winded but it works.
It would be greatly appreciated if anyone could point me in the right direction to being able to get both drop down lists to display alphabetically yet still update the other with the correct value.
Thanks


