pass radio button pick to url | Community
Skip to main content
Charles_Sander1
Level 4
March 16, 2017
Question

pass radio button pick to url

  • March 16, 2017
  • 1 reply
  • 2442 views

A javascript question...

I've got a simple script that will pass my form value to the url in a thankyou page. It doesn't work with radio button fields. When I looked around for other suggestions, the suggestions seem to be using what I've already got. So, I thought maybe somebody here knows what to do - maybe something particular to Marketo.. or I just didn't look hard enough.  My script, currently, which works with the other field types:

<script>

MktoForms2.whenReady(function (form) {

    form.onSuccess(function(values, followUpUrl) {

        var appendEmail = document.getElementsByName('miscInfoField1')[0].value

        location.href = "go.website.com/pagename?choice=" + appendEmail;

        return false;

    });

});

</script>

1 reply

SanfordWhiteman
Level 10
March 16, 2017

Charles, you should be using the values object, not getting a new handle to the DOM element (which is not guaranteed to hold the same value as the underlying field on the form object).

values is already passed to the onSuccess listener and contains the submitted values.

Charles_Sander1
Level 4
March 16, 2017

Something like this? 

MktoForms2.loadForm("//app-ab14.marketo.com","746-PTV-801", 2063, function(form){

     form.onSuccess(function(values, followUpUrl){

          var vals = form.vals();

          location.href = "go.website.com/thanks.html?choice="+vals.miscInfoField1"";

          return false;

     });

});

when I do the above, it only passes the very first value of the radio buttons, regardless which option is chosen.

SanfordWhiteman
Level 10
March 17, 2017

See a couple of extra quotes there, but anyway I can't repro this.  Watch this:

MktoForms2 :: Radio vals

If you point me to the real URL I can tell you what's happening on your site.