pass radio button pick to url

Highlighted

pass radio button pick to url

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 = "http://go.website.com/pagename?choice=" + appendEmail;

        return false;

    });

});

</script>

4 REPLIES 4
Highlighted
Level 10 - Community Moderator

Re: pass radio button pick to url

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.

Highlighted

Re: pass radio button pick to url

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 = "http://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.

Highlighted
Level 10 - Community Moderator

Re: pass radio button pick to url

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.

Highlighted

Re: pass radio button pick to url

Sanford, so sorry! I got sidetracked and we'd decided it was low priority to solve the above problem. So, I never pursued further, and didn't notice your message above, until signing in to ask an unrelated question.

The page is here: Pick your favorite Cupcake

The intention is that, when the user makes their choice, it passes the value to the thanks page and modifies the copy to same something specific to the flavor they chose.