Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Help - how to access text and values from drop-down and list boxes

Avatar

Former Community Member
I know this is probably a very basic question, but the answer has so far eluded me...



Could someone please tell me what code I use to access the text and values in a drop down or list box?



For example, if I want to add an item to a drop-down list, and I put



DropDownList1.addItem(TextField1.rawValue, NumericField1.rawValue);



on a button click event, I get nothing....but when I use



DropDownList1.addItem(TextField1.rawValue);



it works just fine(except it only inserts text, no value).



I saw sample code like that above with a comment saying that the first one was the text, and the second one is the value, but when I try it for myself, it doesn't work, and I'm not even sure how to reference the text or value with an app.alert to see what is there.



I'm using Designer 7.0



Help please! I feel terribly stupid...
4 Replies

Avatar

Former Community Member
Both the text and value for the drop down list are strings. In your code you are passing a number as the value. Try:



DropDownList1.addItem(TextField1.rawValue, NumericField1.rawValue.toString());



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Thank you Chris - the text from the TextField1.rawValue now shows up in the drop down list.



But, when I put



app.alert(DropDownList1.rawValue);



as the second line of code for that button click event, I get a response of "null", which leads me to think that the Numericfield1.rawValue is not being passed to the 'value' column of the drop down list still... Maybe I´m misunderstanding how this works...



Basically what I'm trying to do is set the 'text' and 'value' of the drop down through script rather than manually as I might through the Object palette window.



Am I going about this the wrong way?



Lynne

Avatar

Former Community Member
That's fine. addItem() adds the item to the drop down, but you won't get the value from DropDownList1.rawValue until the user selects a value. At first, the rawValue will be null because no selection has been made.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Thank you, thank you, thank you!!! I knew I was overlooking something... :)



Lynne