/    Sign up×
Community /Pin to ProfileBookmark

passing variables into javascript.

I read another thread that seems to indicate that what I want to do can be done in php. I am quite new to php.

my page is at [url]http://www.stevelim.com/links/links.html[/url]

what I am trying to do is pass parameters from other pages which will determine which CSS id to hide and show.

here is the code that I think I should be using..

[CODE]<?php if($_GET[“type”] == “friends”){
?>
<div id=”friends” style=”display: ””>
<?php
} else {
<div id=”friends” style=”display: ‘none'”>
?>

<?php
}
?> [/CODE]

I get a parse error.

Thanks.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 07.2006 — [code=php]
<?php if($_GET["type"] == "friends"){
?>
<div id="friends" style="display: ''">
<?php
} else {
?>
<div id="friends" style="display: 'none'">

<?php
}
?>
[/code]

Personally, I find it easier to follow the code by not going in and out of PHP mode all the time, but that's more a matter of taste. Here's a cleaner way to do it:
[code=php]
<?php
$style = ($_GET["type"] == "friends") ? '' : 'style="display: none"';
echo "<div id="friends"$style>n";
?>
[/code]
Copy linkTweet thisAlerts:
@supersteve3dauthorMar 07.2006 — NogDog! Thank you! It works wonderfully... amazing this php. I'm often confused where javascript is needed and where php plays its role. I guess there is quite alot of overlap.

As an aside. If I were to get greedy, may I ask if it is possible to sort and rearrange the html such that the variable type passed to the page gets listed first?

Thanks again!
Copy linkTweet thisAlerts:
@supersteve3dauthorMar 07.2006 — Argh. sorry, I just noticed one more thing.

Currently its a if / else thing. What if no type is sent at all? i would like all categories to be open as in my old page.

Should I simple make a 3rd else statement?
Copy linkTweet thisAlerts:
@supersteve3dauthorMar 07.2006 — I think I just need the syntax for the following pseudocode..

$style = ($_GET["type"] == "friends" [B]OR _no type exists[/B]) ? '' : 'style="display: none"';
Copy linkTweet thisAlerts:
@NogDogMar 07.2006 — I think I just need the syntax for the following pseudocode..

$style = ($_GET["type"] == "friends" [B]OR _no type exists[/B]) ? '' : 'style="display: none"';[/QUOTE]

[code=php]
$style = (!isset($_GET["type"]) or $_GET["type"] == "friends") ? '' : 'style="display: none"';
[/code]
Copy linkTweet thisAlerts:
@supersteve3dauthorMar 07.2006 — I got this to work using the following code.

I guess I will address the sorting another time. ?

[CODE]<?php
$style = ($_GET["type"] == "friends" || $_GET["type"] == "") ? '' : 'style="display: none"';
echo "<div id="friends"$style>n";
?> [/CODE]
×

Success!

Help @supersteve3d 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,
)...