GTM Radio Form Field



    Wesley van Wyk

    This code creates a function that takes an input of the name of a radio button, "myRadioButtons". The code then attempts to get an element by that name from the document. If the radio button is checked, the function increments the value of the element, otherwise it returns the text of the radio button.

    function() {
      var radioName = "myRadioButtons";
      try {
        var buttons = document.getElementsByName(radioName);
        for (var i = 0;i < buttons.length;i++){
          if(buttons[i].checked) {
            return buttons[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.