?
Solved

select menu php

Posted on 2007-08-08
9
Medium Priority
?
558 Views
Last Modified: 2013-11-05
Hi

I have a few links.

What I want is a select menu where people select which link they want to browse, and confirm their selection with a button.

So, when they've made a selection and clicked the button, they come to the link they selected. Quite simple.


what would the script be for this?
0
Comment
Question by:ost87
7 Comments
 
LVL 5

Expert Comment

by:RightNL
ID: 19653113


well this ofcourse depends on the source of your link list..

let's say it's an array. and we will have a category with some links...
so we will have fruits (apple, banana) cars(mercedes, bmw) ,

$links = new array();

$links['fruits'] = array('apple' => 'http://apple.yummie', 'banana' => 'http://banana.com');
$links['cars'] = array('mercedus' =>'http://mercedus.com', 'BMW'=>'http://bmw.de');

echo '<select name="category"><option value="">Select a category</option>';
foreach ($links as $key => $value)
{
echo '<option value="'.$key.'" >'.$key.'</option>';
}
echo '</select>';

and in the receiving script ..

if isset($_REQUEST['category'])
{
print_r($links[$_REQUEST['category']);
}
else
{
print_r($links);
}


something like that.. ofcourse it would be a lot easier if you have a database and you can simply add the category to the sql if it is set.

0
 
LVL 16

Accepted Solution

by:
HackneyCab earned 1000 total points
ID: 19653170
I think you'll need Javascript for the effect you're after. PHP cannot talk to the user's browser, so it can't ask for confirmation dialogues to appear.
0
 
LVL 5

Expert Comment

by:RightNL
ID: 19653210
surely you don't need javascript for that..

put this in a file and browse to it..
<?
echo '<form action="" >';
$links = new array();

$links['fruits'] = array('apple' => 'http://apple.yummie', 'banana' => 'http://banana.com');
$links['cars'] = array('mercedus' =>'http://mercedus.com', 'BMW'=>'http://bmw.de');

echo '<select name="category"><option value="">Select a category</option>';
foreach ($links as $key => $value)
{
echo '<option value="'.$key.'" >'.$key.'</option>';
}
echo '</select>';
echo '<input type="submit"></form>';


if isset($_REQUEST['category'])
{
foreach($links[$_REQUEST['category'] as $key => $value);
{
    echo '<a href="'.$value.'">'.$key.'</a><br />';
}
else
{
echo 'select a category first';

}
?>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:ost87
ID: 19653228
Hi RightNL

That script of yours looks pretty elegant, but maybe it's somewhat overkill?

I have 3 static links. I want to put these in a drop down list.
And then a button to confirm the selection.

I do not have different categories or types. Just three links.

Perhaps your script could be simplified to these circumstances? Mind you  I'm not a programmer so I could be talking absolutely no sense when I say this.
0
 
LVL 4

Expert Comment

by:jentulman
ID: 19653458
Will the three links ever change?
Why do you need php to spit it out rather than hard coding it in html?
0
 
LVL 5

Assisted Solution

by:RightNL
RightNL earned 1000 total points
ID: 19653521
ahh.. I then missed your point ...

apologies also to Hackneycab..

yes you should do this with javascript

let me see...

try this

<select name="link" onChange="this.form.submit();" > if you want it to go back to the php page first..

or
<form name="form1"
<select name="link"
 OnChange="location.href=form1.link.options[selectedIndex].value">
<option value="httpadres">name</option>
0
 

Author Comment

by:ost87
ID: 19654017
hi right nl

your second solution works nicely i.e
<form name="form1"
<select name="link"
 OnChange="location.href=form1.link.options[selectedIndex].value">
<option value="httpadres">name</option>

any chance it could save the selection?

also, is cross browser compatible?
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question