javascript help - selectedIndex

They have: 426 posts

Joined: Feb 2005

I am creating a registration form, and part of it is to choose your country, but if the country chosen is United Kingdom i want another drop down box to appear where you can choose your county.

So far what im trying to do is send the selectedIndex.text value into a function called by onclick in the select tag and just give an alert so that i know it is working. But as always it doesnt work first attempt.

This is what i have.
Below creates the select and option boxes. It pulls the countries from the database and generates the option boxes. inside the select tag i have called the function to show an alert box.

<?php
                   
<td class=\"inputbox\">
                        <select name=\"country\" id=\"country\" onclick=\"county(this.option[this.selectedIndex].text)\">
                       
                           
$getCountry = $profile->country();
                            echo
$getCountry;                   
                       
                         </select>                       
                    </td>
?>

below is the javascript to show the alert box.

function county(id){
if(id =="London"){
alert("London");
}
'