Click to See Complete Forum and Search --> : Is this possible?
Anne Vance
10-02-2003, 10:23 AM
On a certain page I click on a button, which then sets a cookie for the url of that particular page.
Then I click on a second button to go to the next page where there is a form where the previous cookie already is printed out.
This form with the url from the cookie is later emailed.
All this works fine.
My question is can I combine the two clicks into one, so that the cookie is set on that page and the form on the next page is opened with the cookie printed out.
requestcode
10-02-2003, 11:07 AM
Probably, but we need to see your code to figure out how.
Khalid Ali
10-02-2003, 11:10 AM
If I understand you correctly, then what you can do is in the function where you read the cookie in the next page,in the same function you can submit the form
Anne Vance
10-02-2003, 12:58 PM
On page 1
I can set a cookie
<title></title>
<script type="text/javascript">
<!--
function write_cookie()
{
var verval =1000*60*60*24;
var nu = new Date();
var vervaltijd = new Date(nu.getTime() +
verval);
vervaltijd = vervaltijd.toGMTString() ;
document.cookie ="bestelling="+document.location +
"; expires=" + vervaltijd + ";" ;
}
// -->
</script>
</head>
and at the bottom there is a button to set the cookie.
also a second button to go to the form
<a href="javascript:write_cookie()">button 1</a>
<a href="bestel.php">button 2</a>
On my form page I can read the cookie, which is already filled into a field.
<title></title>
<SCRIPT LANGUAGE="JavaScript">
<!--
function read_cookie()
{
alert (document.cookie);
}
// -->
</script>
</head>
<TR>
<TD align=right width="20%">Foto</TD>
<TD align=left width="70%"><input type="text" size=70 value=<?php echo $_COOKIE['bestelling']; ?> name="invoer">
</TD>
I need the url of the first page to show in the second page since this url tells me which picture was selected.
I am looking at combining these two buttos to one button on page oneand then go to the form.
Hope it makes sense
Khalid Ali
10-02-2003, 01:18 PM
instead of this
<a href="java script:write_cookie()">button 1</a>
<a href="bestel.php">button 2</a>
use this
<a href="bestel.php" onclick="write_cookie();return true;>new button </a>
requestcode
10-02-2003, 01:36 PM
Or you could change your function to this:
function write_cookie()
{
var verval =1000*60*60*24;
var nu = new Date();
var vervaltijd = new Date(nu.getTime() +
verval);
vervaltijd = vervaltijd.toGMTString() ;
document.cookie ="bestelling="+document.location +
"; expires=" + vervaltijd + ";" ;
location.href="bestel.php"
}
And then just have the one link:
<a href="java script:write_cookie()">button 1</a>
Either way should work.
Anne Vance
10-02-2003, 01:40 PM
Works like a charm !!
thnx Khalid
:D