Add cookie script

Need to add cookie to code that passes info to another page

Page 1 of 1

1 Replies - 2252 Views - Last Post: 25 October 2008 - 11:42 AM

#1 apocalypse57  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-October 08

Add cookie script

Post icon  Posted 20 October 2008 - 06:26 PM

I have a code that I am trying to add cookie script to. When I run the code as listed below, the information from the first page form is passed to the form on the second page. When i add the javascript cookie scripts to the <head> tag, my form disappears. hear is the code for both pages. There are no errors. I am interested in where the cookie script would go.

<HTML>
	<TITLE> Client Information</Title>
<head>
<script type="text/javascript" src="cookie.js">
<!--HIDE FROM INCOMPATIBLE BROWSERS
function addValues()
{
var txtValues
txtValues = document.justcuz.firstName.value;
txtValues = txtValues + document.justcuz.lastName.value;
txtValues = txtValues + document.justcuz.occupation.value;
return txtValues;
}

// STOP HIDING FROM INCOMPATIBLE BROWSERS -->

</script>
</head>
<body>
	<form name="justcuz" action="ServerQueryString.html?txtValues"" onsubmit="addValues()">
<p>First Name <input type="text" name="firstName"/><br />
Last Name <input type="text" name="lastName"/></p>
<p>Occupation<input type="text" name ="occupation"/></p>
<p><input type="submit" /></p>
	</form>
</body>
</html>





<HTML>
	<title>Server Program</title>


<head>
</head>

<body>
		
	<form name="justcuz" action="" onsubmit="">
<p>First Name <input type="text" name="firstName"/><br />
Last Name <input type="text" name="lastName"/></p>
<p>Occupation<input type="text" name ="occupation"/></p>
<p><input type="submit" /></p>
	</form>

<script LANGUAGE="Javascript">
<!--
function replace(string,text,by)
{
	// Replaces text with by in string
	var i = string.indexOf(text), 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;
}

var passed = replace(replace(location.search.substring(1),"+"," "),"=","&");

function split(string,text) 
{
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return;
	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return;
		if (i == -1) 
	{
		splitArray[splitIndex++] = string;
		return;
		}
	splitArray[splitIndex++] = string.substring(0,i);
	if (i+txtLength < strLength)
		split(string.substring(i+txtLength,strLength),text);
	return;
}
// -->
</script>
<script LANGUAGE="Javascript1.1"><!--
function split(string,text)
{
	splitArray = string.split(text);
	splitIndex = splitArray.length;
}
//-->
</script>

<script LANGUAGE="Javascript">
<!--
var splitIndex = 0, splitArray = new Object();

split(passed,'&');

for (var i=0; i < splitIndex; i=i+2)
 {
	if (splitArray[i] == 'firstName')
		document.justcuz.firstName.value = (splitArray[i+1]);
	if (splitArray[i] == 'lastName')
		document.justcuz.lastName.value = (splitArray[i+1]);
	if (splitArray[i] == 'occupation')
		document.justcuz.occupation.value = (splitArray[i+1]);
   }
//-->
</SCRIPT>
	

<A HREF="ClientQueryString.html">Return to data entry page.</A>

</body>





Is This A Good Question/Topic? 0
  • +

Replies To: Add cookie script

#2 JMRKER  Icon User is online

  • D.I.C Addict

Reputation: 125
  • View blog
  • Posts: 818
  • Joined: 25-October 08

Re: Add cookie script

Posted 25 October 2008 - 11:42 AM

I don't know if this will solve the cookie problem as I haven't looked at that part, but I have found that some browsers automatically clear the form or rewrite the page unless I put the following into the onsubmit='' part of your form definition.

Just for grins try putting
1) a onsubmit="addValues();return false"
OR
2) change to onsubmit="return addValues()" with a false/true return statement as the last command in the addValues function.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1