/    Sign up×
Community /Pin to ProfileBookmark

Say if I had several <a> tags and if you rolled over them, a div would show a color depending on the <a> that was rolled over.

I really don’t wanna use js so I was wondering if php would work better.

links.php page:

<?php
$link = $_GET[‘link’];
switch($link) {
case 1:
//some sort of code that changes css background color
break;

case 2:
//some sort of code that changes css background color
break;

}
?>

HTML PAGE:

<a onmouseover=”links.php?link=1″>red</option>
<a onmouseover=”links.php?link=2″>black</option>

<div class=”displayColor”></div>

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@skywalker2208Jan 20.2010 — You can't do this in php unless you want a page refresh. PHP is server side code meaning once the server has served up the page, PHP can no longer making any changes without the help of javascript.

The only way you could do this with php is by having links on the page like
[code=php]<a href="mypage.php?color=red">Red</a>[/code]

If mypage.php is the same name as the page the user is viewing then it will refresh the page with color equal to red in the url. Then you can use php to change the color.

By the way the code you posted with the links which I pasted below is bad html. You have incorrect closing tags.
[code=html]
<a onmouseover="links.php?link=1">red</option>
<a onmouseover="links.php?link=2">black</option>
[/code]


Also, make sure to use code tags to make it easier to read.
×

Success!

Help @bradleybebad 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.1,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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