Giving a dependent drop-down list option a value to create a function
<p>I am very new to Javascript, (first few days)...</p>

<p>Im creating an airline booking form and want to display a seat pitch price dependent on what class the passenger has selected. </p>

<p>Im not to sure how to retrieve a value from the dependent drop-down script so i can create an array to associate the selected value with a price. Heres my script...</p>

<pre><code>&lt;script language="javascript" type="text/javascript"&gt;

function dropdownlist(listindex)
{
    document.flightform.pitch.options.length = 0;
    switch (listindex)
    {
        case "Economy":
            document.flightform.pitch.options[0]=new Option("28","28");
            document.flightform.pitch.options[1]=new Option("29","29");
            break;
        case "Biz":
            document.flightform.pitch.options[0]=new Option("30","");
            document.flightform.pitch.options[1]=new Option("32","");
            break;
        case "First":
            document.flightform.pitch.options[0]=new Option("40","");
            break;
    }
    return true;
}
var Seat_pitch= new Array ();

Seat_pitch["28"] = 400;
//etc.....
//etc.....

function getSeatpitch()
{
    var Seatpitch=0;
    var theForm = document.forms["flightform"];
    var selectedpitch = theForm.elements["pitch"];

    Seatpitch = Seat_pitch[selectedpitch.value];

    return Seatpitch;
}

function calcTotal()
{
    var Total = getSeatpitch()  ;

    //display the result
    var divobj = document.getElementById('totalPrice');
    divobj.style.display='block';
    divobj.innerHTML = "Your flight Total is &amp;pound;"+Total;
}

&lt;/script&gt;

&lt;htmL&gt;
&lt;body&gt;
    &lt;label&gt;Class type&lt;/label&gt;&lt;br /&gt;
    &lt;select id="class"  name='class' onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);"&gt;

        &lt;option value="Economy"&gt;Economy&lt;/option&gt;
        &lt;option value="Biz"&gt;Business&lt;/option&gt;
        &lt;option value="First"&gt;First&lt;/option&gt;
    &lt;/select&gt;
    &lt;br/&gt;&lt;br/&gt;
    &lt;script type="text/javascript" language="JavaScript"&gt;
        document.write('&lt;select name="pitch" id="pitch"&gt;&lt;/select&gt;')
    &lt;/script&gt;
    &lt;div id="totalPrice"&gt;&lt;/div&gt;

&lt;/html&gt;
&lt;/body&gt;
</code></pre>
