Re: PHP / Javascript menu list population
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: PHP / Javascript menu list population

From: Chung Leong <chernyshevsky@hotmail.com>
Date: Sat Oct 29 2005 - 17:08:58 CEST

bigfella wrote:
> Hello Folks,
>
> I would like a web page to have 2 menu lists
>
> The contents of the second menu list depending on the selection made in
> the first.

The easiest way to do this is to create all the secondary menus and
show/hide them depending on the selection of the primary menu.

Example:

<script language="Javascript">

var cur_val = '0';

function ShowSecond(sel) {
        var new_val = '0';
        if(sel.selectedIndex != -1) {
                new_val = sel.options[sel.selectedIndex].value;
        }
        document.getElementById('sel_' + cur_val).style.display = 'none';
        document.getElementById('sel_' + new_val).style.display = 'inline';
        cur_val = new_val;
}

</script>
<select onchange="ShowSecond(this)">
        <option value="0" selected>- Select -</option>
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
        <option value="4">Four</option>
</select>
<select id="sel_1" style="display: none">
        <option>List One</option>
</select><select id="sel_2" style="display: none">
        <option>List Two</option>
</select><select id="sel_3" style="display: none">
        <option>List Three</option>
</select><select id="sel_4" style="display: none">
        <option>List Four</option>
</select><select id="sel_0" disabled>
        <option>Placeholder</option>
</select>
Received on Mon Nov 21 02:52:43 2005