Navigation

    APPDRAG Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular

    REMINDER

    Please be respectful of all AppDragers! Keep it really civil so that we can make the AppDrag community of builders as embracing, positive and inspiring as possible.

    [TM] Change selector with JS

    Cloud CMS (Pagebuilder, Blog, Shop, Newsletters, Code Editor)
    2
    3
    185
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Pierre SULPICE
      Pierre SULPICE last edited by

      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_value

      When I do it, the selection changes well but it's weirdly visible only if I clic on the button, the text doesn't change.
      d3db5677-d963-4b8a-ae2f-907b0ddbd76f-image.png
      (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 result

      Thanks 🙂
      Best regards,

      1 Reply Last reply Reply Quote 0
      • Wassim
        Wassim last edited by

        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");
        
        1 Reply Last reply Reply Quote 0
        • Pierre SULPICE
          Pierre SULPICE last edited by

          That was new to me !
          Thanks a lot sorry for bothering you ^^"

          Good day,
          Best regards

          1 Reply Last reply Reply Quote 0
          • First post
            Last post