REMINDER
[TM] Change selector with JS
-
Hello,
I have a problem using JS to change my selector value.
It's supposed to be as simple as that : https://www.w3schools.com/JSREF/tryit.asp?filename=tryjsref_select_valueWhen I do it, the selection changes well but it's weirdly visible only if I clic on the button, the text doesn't change.
(I ofc tried to print the value in the console, it changed indeed)You can try it here :
https://www.2speak.com/hero2
You can clic on any "Ce pack m'intéresse" button and see the resultThanks
Best regards, -
Hello Pierre,
As you can see it's not a deafult html select element but a Select2 (https://select2.org/getting-started/basic-usage)
To make it update its value when you change it you have to manually trigger the change event after updating the select value:
$("#yourSelect").val("yourvalue"); $("#yourSelect").trigger("change");
-
That was new to me !
Thanks a lot sorry for bothering you ^^"Good day,
Best regards