JS CS3 Dynamic XML Dropmenu
John.Kordas Jun 17, 2009 6:59 AMI'm trying to create a dynamic drop menu dialog that is populated by an xml file. I think I have the xml file setup correctly but not sure how to get the second drop menu to populate according to the first drop menu selection. Would the best way be to have the myDialog.fDetails.fPath.dd.onChange = function () { set the path and section value in var curitem= xmlbooks.path[0].section[0].size.name[j].text();
This is the xml file:
<books>
<path>/c/temp/
<section>Book1
<size>
<name>Double Page Spread 420 x 275</name>
<width>420</width>
<height>275</height>
</size>
<size>
<name>Single Page Spread 210 x 275</name>
<width>210</width>
<height>275</height>
</size>
<size>
<name>1/2 Page Horizontal 180 x 120</name>
<width>180</width>
<height>120</height>
</size>
</section>
<section>Book2
<size>
<name>Double Page Spread 440 x 275</name>
<width>440</width>
<height>275</height>
</size>
<size>
<name>Single Page Spread 220 x 275</name>
<width>220</width>
<height>275</height>
</size>
<size>
<name>1/2 Page Horizontal 120 x 190</name>
<width>120</width>
<height>190</height>
</size>
</section>
</path>
This will run in ESTK
var booksXMLFile = File("/c/booklist.xml");
if(booksXMLFile != null){
var mybooks = booksXMLFile.open("r", undefined, undefined);
if(mybooks == true){
var xmlbooksStr = booksXMLFile.read();
}else{
alert("Could not load booklist.xml file.")
}
booksXMLFile.close();
}
var xmlbooks = new XML (xmlbooksStr);
var mybooks= xmlbooks.path.section.length();
$.write(mybooks);
var myDialog = new Window('dialog', ' Books');
myDialog.fDetails = myDialog.add('panel',undefined,'Book details');
myDialog.fDetails.alignChildren = 'left';
myDialog.fDetails.fPath = myDialog.fDetails.add('group');
myDialog.fDetails.fPath.group = myDialog.fDetails.fPath.add('group');
myDialog.fDetails.fTitle = myDialog.fDetails.add('group');
myDialog.fDetails.btnGroup = myDialog.fDetails.add('group');
with (myDialog.fDetails){
fPath.group.orientation = 'column';
fPath.group.alignChildren = 'right';
fPath.group.preferredSize = [90,15];
fPath.group.st = fPath.group.add('statictext',undefined,'Select Book:');//first drop menu
fPath.dd = fPath.add('dropdownlist', undefined, undefined)
for (i=0;i<mybooks;i++)
{
var curitem= xmlbooks.path.section[i].text();
fPath.dd.add("item",curitem);
}
fTitle.st = fTitle.add('statictext',undefined,'Select Size:');
fTitle.st.preferredSize = [90,15];//second drop menu
fTitle.dd = fTitle.add('dropdownlist', undefined, undefined)
for (j=0;j<mybooks;j++)
{
var curitem= xmlbooks.path[0].section[0].size.name[j].text();
fTitle.dd.add("item",curitem);
}
fTitle.dd.enabled = false;
btnGroup.btn = btnGroup.add('button', undefined, 'Alert Selection');
btnGroup.alignment = 'right';
}
myDialog.fDetails.fPath.dd.onChange = function () {
if(myDialog.fDetails.fPath.dd.selection) {
myDialog.fDetails.fTitle.dd.enabled = true;
}
}
myDialog.fDetails.btnGroup.btn.onClick = function() {
var myValStr
if (myDialog.fDetails.fPath.dd.selection == null ){
myValStr = "Make Book Selection \n"
}else{
myValStr = ""
}
if (myDialog.fDetails.fTitle.dd.selection == null ){
myValStr = myValStr + "Make Size Selection"
}
if(myValStr.length >1){
alert(myValStr);
}else{
myDialog.close();
alert("Thanks for your selections.");
}
}
myDialog.show();

