Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

How to set a dropdown display value

Avatar

Level 2

I know how to access the current value of a dropdown box. But how can I set it?

I have a dropdown box and one of the choices is 'Other'. When 'Other' is selected, a text box is enabled so the user can describe what they mean by 'Other'. Now, I want to make the dropdown more robust where if after selecting 'Other' and providing a comment the user willingly or not makes a different selection, the user is warned that the 'Other' description will be deleted with a choice to proceed or not. If the user proceeds the description is deleted and the text box disabled; if the user doesn't want to proceed with the deletion the text box is left enabled with its value untouched and the dropdown value is reset to 'Other'. This is the part that I can't figure out: how do I reset the display value of the dropdown?

Thanks for the help!

Marc

4 Replies

Avatar

Level 5

Hi,

Can you use

nameOfDropDown.rawValue = "Other";

Hope this helps

Malcolm

Avatar

Level 2

Hi Malcolm,

No, that was my first thought but it didn't work. My understanding is the rawValue property of a dropdown actually refers to the previous selection made and not the current one (displayed value). I have found a fair bit of information on how to access/retrieve the current or previous selection, on how to set the dropdown's selection list, but nothing on how to set the current/displayed value.

Thanks though.

Marc

Avatar

Level 2

Ok, thanks Malcolm. Yes, you were correct about using the rawValue property to reset the selected value of the dropdown.

Why I got so confused is because all my scripting, including trying to reset the newly selected value, was done in the Change event of the dropdown. The rawValue property 'appears' to behave differently here I think because of the order of the events, where it holds the original value through the whole selection process. So essentially, the rawValue during the Change event doesn't hold the newly selected value and will not hold it until the Change event is fully completed.

So I was able to reset the selected value through the Exit event by using a form variable whose value I set in the Change event. So my Change event uses this line at the right location in my script:

cancelDDSelection.value = "yes";

and my Exit event uses the following;

if (cancelDDSelection.value == "yes") //if the Change event reset this form variable to 'yes'
{
this.rawValue = "Other"; //reset the selected value to 'Other'
cancelDDSelection.value = "no"; //reset the form variable to its default value
}

Not sure if there's a better to do this, but all works as I wanted it to now.

Marc

Avatar

Level 1

dropdown.jpg

Hello all,

I need help with drop down list, by default the drop down list box is blank , if a user click down arrow give Add Remove option , i want to create a empty area where if a user accidently clicked the drop down and they want the field to go back to default (Blank).

Thanks in advance.