YUI Custom Event for Dropdown value pre-selection?
-
18-09-2019 - |
Question
I have a dropdown field and its value is pre-selected as soon as its rendered(Say, its a Country field in a signup form). And I have other dropdowns or other components which change the selected value of the first dropdown dynamically. Now I want to fire a method with every "value getting selected" in the dropdown. Is it possible?
To put my question in much more clearer way, I want to create a "onDefaultValueSet" event and subscribe the first dropdown to it. So in which ever way the dropdown gets any value selected, the corresponding handler(my function)gets called.
I tried to do it with YUI Custom Events, but I am not sure how the browser will be calling(understanding) my handler everytime a value is selected in the dropdown.
onSelect(from Default DOM) is not a right answer I guess, as I tried it.
Please help me in tackling this problem
Solution
I am not sure whether this is an answer, but I've found a workaround. Please validate this.
So I was making a item "selected" using javascript-dom manipulation. Meaning, using
domElement.options[5].selected = True;
So with the (YUI)custom event I created, I started calling "fire()" right after this. So the code becomes:
domElement.options[5].selected = True;
onDefaultValueSetEvent.fire(domElement.name);
But I am not sure, what if the particular option is selected in a gui fashion. Meaning, how automatically fire() method is called