Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing a Cookie

Status
Not open for further replies.

cdumigan

MIS
Feb 5, 2002
16
0
0
IE
Hi there,
I want to create a cookie to pass variables between forms. I have 5 text areas called v_name, v_age, v_DOB, v_nation, and v_sex on a from called 'Details'. I wish to store these values in a cookie and pass them to a second form called 'Extra Details'. Problem is I'm attrocious at writing cookies. Can anyone help??
Thanks in advance,
Conor
 
If it's for passing values from one form to the other, you don't really need cookies. Watch this:

Put this in the <head> of the first form:

<SCRIPT Language=&quot;JavaScript&quot;>
<!--
function passvalues() {
window.location.href = &quot;recieve.htm?v_name.value='&quot;+escape(document.forms.Send.v_name.value)+
&quot;'&v_age.value='&quot;+escape(document.forms.Send.v_age.value)+
&quot;'&v_DOB.value='&quot;+escape(document.forms.Send.v_DOB.value)+
&quot;'&v_nation.value='&quot;+escape(document.forms.Send.v_nation.value)+
&quot;'&v_sex.value='&quot;+escape(document.forms.Send.v_sex.value)+&quot;'&quot;

}
//-->
</script>

And the form should be like this:

<FORM name=&quot;Send&quot;>
Name:<INPUT name=&quot;v_name&quot; type= &quot;textfield&quot;><br>
Age:<INPUT name=&quot;v_age&quot; type=&quot;textfield&quot;><br>
DOB:<INPUT name=&quot;v_DOB&quot; type=&quot;textfield&quot;><br>
Nation:<INPUT name=&quot;v_nation&quot; type=&quot;textfield&quot;><br>
Sex:<INPUT name=&quot;v_sex&quot; type=&quot;textfield&quot;><br>
<INPUT onclick=passvalues() type=button value=&quot;Send&quot;>
</FORM>

In the form that this input wil recieve (recieve.htm in my script), put this in the <head>:

<script Language=&quot;JavaScript&quot;>
<!--
function getFromSearch() {
var x = 0
mySearch = location.search.substr(1).split(&quot;&&quot;)
for (x=0;x<=mySearch.length;x++) {
eval(&quot;document.forms.Form.&quot;+unescape(mySearch[x]))
}
}
//-->
</script>

And to activate this:

<body onLoad=&quot;getFromSearch()&quot; bgcolor=&quot;#FFFFFF&quot;>

<form method=&quot;post&quot; action=&quot;&quot; name=&quot;Form&quot;>
<INPUT name=&quot;v_name&quot; type= &quot;textfield&quot;>
<INPUT name=&quot;v_age&quot; type=&quot;textfield&quot;>
<INPUT name=&quot;v_DOB&quot; type=&quot;textfield&quot;>
<INPUT name=&quot;v_nation&quot; type=&quot;textfield&quot;>
<INPUT name=&quot;v_sex&quot; type=&quot;textfield&quot;>
<input type=&quot;submit&quot; value=&quot;Order&quot;>

Hope this helps,

Quasibobo

Don't eat yellow snow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top