Inserting one static link into a dynamic drop down list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LizzyD
Forum Newbie
Posts: 22
Joined: Mon Oct 04, 2004 5:36 am

Inserting one static link into a dynamic drop down list

Post by LizzyD »

Hello!

Does anyone know if there's a way to either insert a static link into a dynamic drop down list, or alternatively how to make the whole drop down list static?

here is my list:

Code: Select all

<?php 
//create form containing selection list     
    echo "<form action='../en/showhotels.php' method='get'> 
           
          <table width='300' height='25' align='right' border='0' cellpadding='0' cellspacing='0'> 
          <tr> 
          <td align='right' valign='middle' class='countylist'> 
             
          <select name='County' onchange='submit()' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; padding:0; border:0; margin:0; width:164px;'> 
           
    <option value='' selected>Select County 
    <option value='Avon'>Avon     
    <option value='Bedfordshire'>Bedfordshire 
    <option value='Berkshire'>Berkshire 
    <option value='Buckinghamshire'>Buckinghamshire 
    <option value='Cambridgeshire'>Cambridgeshire 
    <option value='Cheshire'>Cheshire 
    <option value='Cleveland'>Cleveland 
    <option value='Cornwall'>Cornwall 
    <option value='County Durham'>County Durham 
    <option value='Cumbria'>Cumbria 
    <option value='Derbyshire'>Derbyshire 
    <option value='Devon'>Devon 
    <option value='Dorset'>Dorset 
    <option value='Durham'>Durham 
    <option value='East Sussex'>East Sussex 
    <option value='Essex'>Essex 
    <option value='Gloucestershire'>Gloucestershire 
    <option value='Greater London'>Greater London 
    <option value='Greater Manchester'>Greater Manchester 
    <option value='Guernsey'>Guernsey     
    <option value='Hampshire'>Hampshire 
    <option value='Herefordshire'>Herefordshire 
    <option value='Hertfordshire'>Hertfordshire 
    <option value='Humberside'>Humberside 
    <option value='Isle of Wight'>Isle of Wight 
    <option value='Isle of Man'>Isle of Man 
    <option value='Jersey'>Jersey     
    <option value='Kent'>Kent 
    <option value='Lancashire'>Lancashire 
    <option value='Leicestershire'>Leicestershire 
    <option value='Lincolnshire'>Lincolnshire 
    <option value='London'>London 
    <option value='Merseyside'>Merseyside 
    <option value='Norfolk'>Norfolk 
    <option value='North Yorkshire'>North Yorkshire 
    <option value='Northamptonshire'>Northamptonshire 
    <option value='Northumberland'>Northumberland 
    <option value='Nottinghamshire'>Nottinghamshire 
    <option value='Oxfordshire'>Oxfordshire 
    <option value='Somerset'>Somerset 
    <option value='Surrey'>Surrey 

                               
          </select> 
             
          </td> 
          </tr> 
          </table> 
             
          </form>";             
?>
On the Greater London option, I want users to be directed to http://www.hotelheaven.co.uk/en/london.php (as opposed to http://www.hotelheaven.co.uk/en/showhot ... ter+London like all the rest)....

I'd be very very grateful if anyone can explain it to me or send me to a tutorial. I've been searching for ages with no luck!

LizzyD
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

You can use javascript to change the action of the form when the user selects london. Or you could check to see what the user selected on the next page and then redirect the user to the london page if you have to.
LizzyD
Forum Newbie
Posts: 22
Joined: Mon Oct 04, 2004 5:36 am

Post by LizzyD »

thanks for replying kettle drum. someone has actually suggested that I put the following in the header

<script language="javascript">
<!-- Begin
function route() {
if (document.form.county.value) == "Greater London" {
Window.location = "http://www.hotelheaven.co.uk/en/london.php"
}
else {
Window.location = "http://www.hotelheaven.co.uk/en/showhotels.php?" + document.form.county.value
}
// End -->
</script>

However, I don't know anything about javascript and can't get this to work. I'd be more than happy to redirect the user from the next page too but i don't know how to do that either! would appreciate some advice!

LizzyD
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

I assume you have a database which you have access to. Why not simply have a table in the DB table indicating the url location as well as other possible information:

example table dummyCounty has columns:county_id, short_name, url_dest

Your option list could be built as <option value=[county_id]>[short_name]</option> retrieved from the database.

When processing the $_POST in php simply get the value and query the database for the location.
You can then use the php command "header" to move to the correct location.
Post Reply