/    Sign up×
Community /Pin to ProfileBookmark

click image, transfer page

I have an image. Its onclick property sends it to a function. Now how do I make it link to another page after the stuff in the function is complete. Think of it this way. On page 1, I click an image. It does some calculating in a function, and then transfers me to page 2. How do I do this?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@MstrBobJul 09.2004 — Well, since PHP is all server side, the onclick function won't work like it will in JavaScript.

<i>
</i>&lt;a href="&lt;?PHP echo($_SERVER['PHP_SELF']); ?&gt;?func=1"&gt;&lt;img src="mypic.jpg" alt="My pic"&gt;&lt;/a&gt;


This is sending the browser to the same page, only now it's passing the variable 'func' with the value of 1. Now, in this page you have:

[code=php]
if(isset($func) && $func == 1)
{
...script here ...
header("Location: page2.php");
} else {
[/code]

...the rest of your page, and at the bottom, finish with a closing ' } '.

The if statement is basically saying if the variable 'func' is set, and the value equals 1, then do you script. The bottom header function sends to another page.
×

Success!

Help @theuedimaster 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...