Anyone know why this javascript would read the element ID just fine but then not extract the value? The popup shows the correct element ID (i.e. matches the one shown in the browser console on inspect) but the value is empty (no error).
var dummy Elements = document.getElementsByClassName("dummy-class-name");
if (dummyElements.length > 0) {
var dummyVal = document.getElementById(dummy Elements[0].id).value;
alert ("id: " + dummyElements[0].id + ", val: " + dummyVal);
}
I've also tried:
alert (document.getElementsByClassName("dummy-class-name")[0].value);
And that is empty too with no error. Both queries (getElementsByClassName and getElementsByClassName) show the correct value when inspecting using the console though. If it was a timing issue I would've thought it wouldn't read the ID either, so I'm assuming it's not that.
What I want to do is read what text the user has entered in a search dropdown after they hit Enter, which triggers the on params change event, and that's where I have my javascript. I'm not able to read the widget ID at runtime because it's a child object embedded within the Outsystems dropdown search widget and so I only have access to the parent ID. The project is web reactive.
NOTE: "var dummy Elements" at the beginning should be "var dummyElements" - it was changed by autocorrect. Though that said, in reality it would be better to have "let dummyElements".
Thinking about it again, maybe it is a timing issue as the widget will already be rendered and it's the user input I'm after. But then again, it's after hitting enter so should be sufficient time between typing and the on change event being triggered (no onblur available).
From another forum post it looks like it used to work this way but I know the widget has changed. Really does feel like this is something that should be built into the widget.
Hi Sienna,
If you are trying to get some text inside a div you should try to get the innerHTML instead of the value property.
The value property is normally used for input elements and the innerHTML for divs.
So I would suggest trying this:
var dummyElements = document.getElementsByClassName("dummy-class-name");
var dummyVal = document.getElementById(dummyElements[0].id).innerHTML;