|
I'm new to Javascript so I appreciate your help. I have a site that has serveral downloads. The owner of the site wants to collect user information everytime someone downloads. A nuisance if you've already visited and have to fill out a form. I want to place a cookie the first time they download so that the second time the form gets pre-populated for them. I found a site that had a walkthrough on how to do this but my code isn't working. It either isn't writing the cookie, retrieving the cookie or both. Thanks in advance for your help.
Here's the Javascript code I created...
<script type="text/javascript">
//************************
// Set MDF Cookie and File to download
//************************
function Get_Cookie(name) {
var start = document.cookie.indexOf(name+"=");
var len = start+name.length+1;
if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
if (start == -1) return null;
var end = document.cookie.indexOf(";",len);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(len,end));
}
function Set_Cookie(name,value,expires,path,domain,secure) {
document.cookie = name + "=" +escape(value) +
( (expires) ? ";expires=" + expires.toGMTString() : "") +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
( (secure) ? ";secure" : "");
}
function setDownloadOption() {
//alert (queryString('file'));
document.downloadForm.file.value = queryString('file');
if (document.downloadForm.file.value.length < 1) document.downloadForm.file.value = 'ims45full';
if (userProfile) getValues(userProfile);
}
function getValues(string) {
getValue(string,"name", document.downloadForm.name, "text");
getValue(string,"company", document.downloadForm.company, "text");
getValue(string,"email", document.downloadForm.email, "text");
getValue(string,"phone", document.downloadForm.phone, "text");
getValue(string,"city", document.downloadForm.city, "text");
getValue(string,"state_region", document.downloadForm.state_region, "text");
getValue(string,"country", document.downloadForm.country, "select");
}
function replace(string,text,by) {
// Replaces text with by in string
var i = string.indexOf(text);
var newstr = '';
if ((!i) || (i == -1)) return string;
newstr += string.substring(0,i) + by;
if (i+text.length < string.length)
newstr += replace(string.substring(i+text.length,string.length),text,by);
return newstr;
}
function getValue(string,elementName,object,elementType) {
// gets value of elementName from string and populates object of elementType
var startPos = string.indexOf(elementName + "=")
if (startPos > -1) {
startPos = startPos + elementName.length + 1;
var endPos = string.indexOf("&",startPos);
if (endPos == -1) endPos = string.length;
var elementValue = unescape(string.substring(startPos,endPos));
if (elementType == "text") object.value = elementValue;
if (elementType == "password") object.value = elementValue;
if (elementType == "select") object.selectedIndex = elementValue;
if (elementType == "checkbox") object.checked = onCheck(elementValue);
if (elementType == "radio") object[elementValue].checked = true;
}
}
</script>
The body onload looks like this...
<body onload="setDownloadOption();">
Thanks
jodtoad
|
|
|
|
|
|
|
© Copyright codetoad.com 2001-2004 |
|
|