Skip to main content
bagonterman
Inspiring
April 6, 2012
Answered

onChange change dropdownlist?

  • April 6, 2012
  • 3 replies
  • 3809 views

I am using a dropdown list to make a selection and then based on that selection I would like the second dropdown list to change based on the election.

myStandardDown.onChange = function () {if (myStandardDown.selection==1){myTypeDown = ("dropdownlist", undefined, lithoNames);}}

I tried something like this and,

this:

if (myStandardDown.selection==0){myTypeDown =myInputGroup.add ("dropdownlist", undefined, execNames);}

or

myStandardDown.onChange = function () {if (myStandardDown.selection==1){myTypeDown.graphics = ("dropdownlist", undefined, lithoNames);}}

I don't know. The end result I am going to have many things change based on this so this is the crux of it.

I can get a text edit box to change but that is it.

I have three different drop downs that it needs to change into.

If you can lead me in the right direction it would be appreciated.

This topic has been closed for replies.
Correct answer bagonterman

So I think I have figured it out although if you have a better way of righting this feel free to post but this works.

myStandardDown.onChange = function () {if (myStandardDown.selection==1){while (myTypeDown.items.length> 0) {myTypeDown.remove (myTypeDown.items[0]);}

            for (var i = 0; i <lithoNames.length; i++){myTypeDown.add ("item", (lithoNames));}myTypeDown.selection=0}

        else if (myStandardDown.selection==2){while (myTypeDown.items.length> 0) {myTypeDown.remove (myTypeDown.items[0]);}

            for (var i = 0; i <embossNames.length; i++){myTypeDown.add ("item", (embossNames));}myTypeDown.selection=0}

        else{while (myTypeDown.items.length> 0) {myTypeDown.remove (myTypeDown.items[0]);}

            for (var i = 0; i <execNames.length; i++){myTypeDown.add ("item", (execNames));}myTypeDown.selection=0}}

basically on change it deletes the list from the drop down in a while loop then adds a list back in with a for loop depending on the selection that was made on change.

3 replies

bagonterman
bagontermanAuthorCorrect answer
Inspiring
April 9, 2012

So I think I have figured it out although if you have a better way of righting this feel free to post but this works.

myStandardDown.onChange = function () {if (myStandardDown.selection==1){while (myTypeDown.items.length> 0) {myTypeDown.remove (myTypeDown.items[0]);}

            for (var i = 0; i <lithoNames.length; i++){myTypeDown.add ("item", (lithoNames));}myTypeDown.selection=0}

        else if (myStandardDown.selection==2){while (myTypeDown.items.length> 0) {myTypeDown.remove (myTypeDown.items[0]);}

            for (var i = 0; i <embossNames.length; i++){myTypeDown.add ("item", (embossNames));}myTypeDown.selection=0}

        else{while (myTypeDown.items.length> 0) {myTypeDown.remove (myTypeDown.items[0]);}

            for (var i = 0; i <execNames.length; i++){myTypeDown.add ("item", (execNames));}myTypeDown.selection=0}}

basically on change it deletes the list from the drop down in a while loop then adds a list back in with a for loop depending on the selection that was made on change.

bagonterman
Inspiring
April 9, 2012

Ok I feel like I am getting somewhere but I still need help.

using and example for lists shown in scriptui-1-9 I can add to my drop down menu an item. However I want to replace those items depending on other selections. So I need to remove multiple items and replace them with multiple items.

myStandardDown.onChange = function () {if (myStandardDown.selection==1){myTypeDown.add ("item", lithoNames)}}

this will add but it only adds one line I need it to be a menu with multiple lines. I also need to remove all the other Items in the dropdown.

I hope this is clear.

bagonterman
Inspiring
April 9, 2012

So now I am able to respond to an event a selection in a dropdown and now I am deleting the list and adding a new set of values into the list but when I add it adds the whole list not in a drop down.

myStandardDown.onChange = function () {if (myStandardDown.selection==1){while (myTypeDown.items.length> 0) {myTypeDown.remove (myTypeDown.items[0]);}myTypeDown.add ("item", lithoNames);}}

If I can figure this then I will have it.

bagonterman
Inspiring
April 6, 2012

I have tried this to

myStandardDown.onChange = function () {if (myStandardDown.selection==1){myTypeDown =myInputGroup.add ("dropdownlist", undefined, lithoNames); myTypeDown.selection = myTypeDown.items[0];}}

it did not change.

bagonterman
Inspiring
April 6, 2012

You can specify the choice items on creation of the list object, or afterward using the list object’s add() method.

Taken from javaScript Tools Guide.

ListItem

Items added to or inserted into any type of list control are ListItem objects, with properties that can be manipulated from a script. ListItem elements can be of the following types: uitem: the typical item in any type of list. It displays text or an image, and can be selected. To display an image, set the item object’s image property;

also taken from javaScript Tools Guide.

I still do not get it.

bagonterman
Inspiring
April 6, 2012

if a dropdown list can not be changed using onChange let me know I will try and go in a different direction.