PDA

View Full Version : Selecting the contents of a pulldown via a button


Griz
01-20-2003, 09:57 PM
I have a pulldown that I populate in the begining of the movie list this:

comboBox1.addItem("ALVORD", new Array("ALVORD street, for William Alvord. ", "alvord"));
comboBox1.addItem("BAKER", new Array("BAKER street, for Colonel E. D. Baker. ", "baker"));

Is there anyway to select an item in the pulldown via another button, that is, in this case if I made an "alvord" button in another sceen when pressed would select that entry in the pulldown?

thanks in advance.

freddycodes
01-20-2003, 10:21 PM
Why do you have the data element for the drop down list set to an array. Just wondering thats all.

Anyways with the way you have things this would work. Where setAlvord() is the function assigned to the button.


comboBox1.addItem("BAKER", new Array("BAKER street, for Colonel E. D. Baker. ", "baker"));
comboBox1.addItem("ALVORD", new Array("ALVORD street, for William Alvord. ", "alvord"));

function setAlvord() {
var idx = getIndex("alvord");
comboBox1.setSelectedIndex(idx);
}

function getIndex(what) {
var numItems = comboBox1.getLength();
for(var i = 0;i<numItems;i++) {
var tmpArr = comboBox1.getItemAt(i).data;
if(tmpArr[1] == what) {
return i;
}
}

}

Griz
01-20-2003, 10:30 PM
I used array because I was not sure how else to do it... Is there a easier way?

Basically, each entry in the pulldown has two pieces of data; the text description of the street and the name of the MC to play in a display window.

The reason I want access this pulldown via button is that I have a map with some of the streets, and I don't want to keep data in two locations - If I use the pulldown as the master place for all of the data, then call that from the map button, If something changes, I won't have to update in two places.

freddycodes
01-20-2003, 10:39 PM
Like this:


comboBox1.addItem("BAKER", "BAKER street, for Colonel E. D. Baker. ");
comboBox1.addItem("ALVORD", "ALVORD street, for William Alvord. ");

function setAlvord() {
var idx = getIndex("ALVORD");
comboBox1.setSelectedIndex(idx);
}

function getIndex(what) {
var numItems = comboBox1.getLength();
for(var i = 0;i<numItems;i++) {
if(comboBox1.getItemAt(i).label == what) {
return i;
}
}

}

Griz
01-20-2003, 10:48 PM
Opps, I probably should mention this:

Not all of the MC names match the street name exactly, since some are duplicated, so that why I used the array:

comboBox1.addItem("BAKER", new Array("BAKER street, for Colonel E. D. Baker. ", "shipimage "));

where "shipimage" would be a MC of a ship.

So lets say that on the map I have the street named "baker". I want to read the comboBox array for baker and display it's text and MC.

thanks for your help, BTW

freddycodes
01-20-2003, 10:50 PM
Okay then go with the array and use the code like I posted first.

Griz
01-22-2003, 08:52 PM
Thanks for your help - it worked fine.

I now have to add about 10-20 buttons on the map and I was wondering if there was a way to 'generizing' the function so that I can past the street name to it and have it get the two pieces of information for me.

For example, for the 'ALVORD' button, would call the function by passing an 'ALVORD' string to it to get the two pieces of data...