/    Sign up×
Community /Pin to ProfileBookmark

Dropdown reading array and onclick

Hello, i am all new to this kind of stuff and i didnt find any topic yet about it because i do not really know how to call this problem. So if there are any solutions yet i am sorry for opening a new topic.

I want a dropdown navigation, that read its content out of an array.

thats what i got so far and it works.

[CODE]<?
echo ‘<SELECT name=bild>’;

foreach ($zahl_array as $key => $value)
{
echo ‘<OPTION value=’.$value.’> ‘.$value.”;
}
echo ‘</select>’;
?>
[/CODE]

$zahl_array is reading the array content out of a .txt file.

Now the problem is that i want something to happen when you change/click on one link in the dropdown.

Above this code, there is a table with an randomly generated Image.

[CODE]
$zahl_array = file(‘zahl.txt’);
$num = rand(0, count($zahl_array) – 1);
$zahl = $zahl_array[$num];
…html…<img src=”/images/<? echo $zahl; ?>.jpg”>…html…
[/CODE]

Now if the user chooses one link in the dropdown it should change the Image above to the one that the user choosed.

Sry for bad english i am from germany

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@YelgnidrocJan 05.2010 — If you want something to happen when something is clocked, you need Javascript onclick() function.

I'm not a big Javascripter, so you'd be better off asking in the Javascript forum
Copy linkTweet thisAlerts:
@ExkingauthorJan 05.2010 — I know that there are several options in javascript with all the event handlers, but i did all parts yet in php and i try keeping it Server sided.

I just feel more comfortable when i know that the user does not need to have anything like javascript turned on.
Copy linkTweet thisAlerts:
@dk_zero-coolJan 05.2010 — There are no users without javascript. It would almost be impossible to surf the web to day without it, since most websites to day uses 60&#37; or more javascript. Many websites even use javascript to load content from the server.

If you want to make a drop-down menu with PHP, it would require re-loading the page every time something should be changed. Don't think many users would stay on that site for to long. Some things are just not meant for server side scripting.

Search google for javascript drop down menus, and get a real menu. Avoid CSS menus, as they don't work proper in all browsers.
Copy linkTweet thisAlerts:
@devgooruJan 06.2010 — I think css menus are working quite well on all browsers if coded properly and simpler to use than javascript. Remember, one javascript error can prevent other code from executing properly and poof...there goes your menu.
Copy linkTweet thisAlerts:
@ExkingauthorJan 06.2010 — OK guys thx so far, i give it a try with the javascript
×

Success!

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