/    Sign up×
Community /Pin to ProfileBookmark

Is this possible?

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.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@requestcodeOct 02.2003 — Probably, but we need to see your code to figure out how.
Copy linkTweet thisAlerts:
@Khalid_AliOct 02.2003 — 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
Copy linkTweet thisAlerts:
@Anne_VanceauthorOct 02.2003 — 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
Copy linkTweet thisAlerts:
@Khalid_AliOct 02.2003 — 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>
Copy linkTweet thisAlerts:
@requestcodeOct 02.2003 — 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.
Copy linkTweet thisAlerts:
@Anne_VanceauthorOct 02.2003 — Works like a charm !!

thnx Khalid

?
×

Success!

Help @Anne_Vance spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...