简体   繁体   中英

Pass JS variable to HTML form onsubmit - Mailchimp embed form

I have a form that I am trying to pass a JavaScript variable into. The custom hidden field works, but nothing gets passed into it... is there something wrong with the onsubmit code?

Embedded form code:

<input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email" required>
<input type="hidden" name="REFERID" id="MERGE1" value="">

Here is the JS Code later in the page:

<script type="text/javascript">

function addref() {
    var urlref = (document.url);
    var refcode = urlref.substring(urlref.indexOf "ref" +4 != urlref.length);

            document.mc-embedded-subscribe-form.MERGE1.value = refcode;
}
    </script>

尝试使用:

document.getElementById("MERGE1").value = refcode;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM