Page 1 of 1

Inserting one static link into a dynamic drop down list

Posted: Thu Dec 02, 2004 5:15 am
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

Posted: Thu Dec 02, 2004 6:01 am
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.

Posted: Thu Dec 02, 2004 6:15 am
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

Posted: Thu Dec 02, 2004 7:06 am
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.