当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Need to pass cookie values to hidden fields in Infusionsoft Form

问题描述:

I've been trying to modify some javascript provided by this gentleman - http://www.terminusapp.com/blog/add-utm-referrer-lead-forms/

However the instructions he provided simply don't work for Infusionsoft. I've been able to get the Javascript code functional to actually write the cookie, but I'll need to manually get it input in this form. The field in the form is programmed this way


<div class="infusion-field">

<label for="inf_custom_LastReferrer0">Last Referrer</label>

<input class="infusion-field-input-container" id="inf_custom_LastReferrer0" name="inf_custom_LastReferrer0" type="hidden" />

</div>


The cookie being created is named "_uc_last_referrer" with the value "https%3A//www.google.com" Obviously that value will change depending on who the original referrer was.

What I need is to input that value into the hidden field contained in the form. There's actually four cookie values that I need to input into 4 hidden fields, but I'm assuming once I see how to do one I can do repeat and change the text as needed for the other three.

I've searched on the site of course, because a million people have asked this question, but I don't have a good enough grasp of Jquery yet to be able to figure out how to tweak it for the Infusion form. If anyone could help me out I'd greatly appreciate it.

网友答案:
(function(){
    var cookies;

    function readCookie(name,c,C,i){
        if(cookies){ return cookies[name]; }

        c = document.cookie.split('; ');
        cookies = {};

        for(i=c.length-1; i>=0; i--){
           C = c[i].split('=');
           cookies[C[0]] = C[1];
        }

        return cookies[name];
    }

    window.readCookie = readCookie; 
})();

$(document).ready(function(){
    //Get cookie you want.
    var referrer = window.readCookie('readCookie_uc_last_referrer') || ''; 
    //Set cookie value to hidden field.        
    $('#inf_custom_LastReferrer0').val(referrer);
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: