I'm trying to set up a system on my site so that users who come through a custom link get tagged with a cookie that triggers a specific code to replace the default part of a signup form. The desired result is, in this example, for someone coming to http://example.com/?=mylink1 getting tagged with a cookie that changes the "value" attribute in any inputs with id #xcode to "X190". What I have so far:
Create cookie from query string:
function cookieQuery() {
var url = window.location.href;
if(url.indexOf('?' + mylink1) = 1)
document.cookie="cookie1";
}
Check cookie and if true change attribute value with Jquery, if no cookie, do nothing:
function readCookie(cookie1) {
var nameEQ = cookie1 + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0)
$("#xcode").attr("value","X190");
}
return null;
}
I appreciate any help figuring this out!