How to get selected value from drop down using JavaScript action

0
Hello, i wrote javascript code in javascript action i am calling javascript action through nanoflow which gets called when user selects dropdown  but i am getting error as undefined whenever nanoflow is triggered,
asked
5 answers
0

Hi Avanti,

To my current javascript knowledge it looks like your variable e on line 19 is empty. Which causes line 20 to crash as it can not get a value from something that is undefined. 

Also if i'm not mistaken you should use somethin like this:
 

let elements = document.getElementsByClassName('');

This returns an array with all elements found. which then you have to loop over to get the right element.  In that loop you can also get the value.

Hopefully this points you in the right direction.

Kind regards,
Brandon

answered
0

Hi Avanti,

var e = window.getElementsByClassName('mx-name-customDropDown2')[0];

replace line 19  OR
add "[0]" in the end

 

Please accept the Answere, it helps:)

answered
0

Hi Waleed i have made changes at line 19 but it is still not working

 

answered
0

Hi Brandon Kleijnen i have made changes at line 19 but it is still not working it giving blank data


 

answered
0

Okay interesting.. 
Have you tried to debug the result set of "let elements"?
Seems to me that it can't find the dropdown. 
This may be causes by several things, for example the classname provided isn't the correct one.

In your picture you provided no classname has been provided.

I've tested some things out and get this in my console:


So I was able to get the element.
Problem is this gives me the complete row. So if I want to get the input I would have to go deeper with Children. 
I haven't worked much with JS in mendix yet and this seems a bit over the top.

But I hope my answer helps you a bit.
Ps. This is my Js code.

answered