GTM. Select Form Field



    Wesley van Wyk

    The code looks for a select element with the ID "mySelectList" and extracts its options. It then iterates through the options, looking for ones that are selected. If one is found, the value of that option is returned.

    function() {
      var selectId = document.getElementById("mySelectList");
      try {
        var options = selectId.options;
        for (var i = 0;i < options.length;i++){
          if(options[i].selected) {
            return options[i].value;
      } catch(e) {}
      return "";
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.