Q:

Changing the value of a second drop down menu based on selection from another

I have two drop down menu's for age, age from, and age to. Values within these drop downs range from 17-50.
If from the first drop down, a user selects 25 then in the second box, the user can choose a value lower than that which would not be ideal, nor would it make sense. Is there a way to get the second drop down to begin after the selection from the first drop down? So if a user selects age 25 from the first drop down, the second drop down would begin from 26.
Just as a further check, a user may go onto the second drop down first, selecting an option which would invalidate the above check. In such a case, is there also a way to only enable to second drop down after the first one has been selected?
Here is how my drop downs are defined:
Age from:
                            <select> 
                            <option value="none"></option>
                                <?php
                                    for ($i=17; $i<=50; $i++)
                                    {
                                        ?>
                                            <option value="<?php echo $i;?>"><?php echo $i;?></option>
                                        <?php
                                    }
                                ?>
                                </select>
                                to: 
                            <select> 
                            <option value="none"></option>
                                <?php
                                    for ($i2=18; $i2<=50; $i2++)
                                    {
                                        ?>
                                            <option value="<?php echo $i2;?>"><?php echo $i2;?></option>
                                        <?php
                                    }
                                ?>
                                </select>

A:

Try this, you can't have one without the other:
Age from:
<select id="age_a" onchange="checkages_a()"> 
    <option value="none"></option>
<?php
    for($i = 17; $i <= 49; ++$i) {
        echo "\t", '<option value="', $i, '">', $i, '</option>', "\n";
    }
?>
</select>
to: 
<select id="age_b" onchange="checkages_b()"> 
    <option value="none"></option>
<?php
    for($i = 18; $i <= 50; ++$i) {
        echo "\t", '<option value="', $i, '">', $i, '</option>', "\n";
    }
?>
</select>

Version A
<script type="text/javascript">
var age_a = document.getElementById("age_a");
var age_b = document.getElementById("age_b");

function checkages_a() {
    var a = typeof(age_a.options[age_a.selectedIndex]) !== 'undefined' ? age_a.options[age_a.selectedIndex].value : 0;
    var b = typeof(age_b.options[age_b.selectedIndex]) !== 'undefined' ? age_b.options[age_b.selectedIndex].value : 0;
    if(b == 'none' || a > b)
        age_b.selectedIndex = age_a.selectedIndex - 1;
}

function checkages_b() {
    var a = typeof(age_a.options[age_a.selectedIndex]) !== 'undefined' ? age_a.options[age_a.selectedIndex].value : 0;
    var b = typeof(age_b.options[age_b.selectedIndex]) !== 'undefined' ? age_b.options[age_b.selectedIndex].value : 0;
    if(!b || b == 'none')
        age_b.selectedIndex = age_a.selectedIndex - 1;
    if(a == 'none' || b < a)
        age_a.selectedIndex = age_b.selectedIndex + 1;
}
</script>

Version B
<script type="text/javascript">
var age_a = document.getElementById("age_a");
var age_b = document.getElementById("age_b");

function checkages_a() {
    var a = typeof(age_a.options[age_a.selectedIndex]) !== 'undefined' ? age_a.options[age_a.selectedIndex].value : 0;
    var b = typeof(age_b.options[age_b.selectedIndex]) !== 'undefined' ? age_b.options[age_b.selectedIndex].value : 0;
    if(b == 'none' || a >= b)
        age_b.selectedIndex = age_a.selectedIndex;
}

function checkages_b() {
    var a = typeof(age_a.options[age_a.selectedIndex]) !== 'undefined' ? age_a.options[age_a.selectedIndex].value : 0;
    var b = typeof(age_b.options[age_b.selectedIndex]) !== 'undefined' ? age_b.options[age_b.selectedIndex].value : 0;
    if(!b || b == 'none')
        age_b.selectedIndex = age_a.selectedIndex;
    if(a == 'none' || b <= a)
        age_a.selectedIndex = age_b.selectedIndex;
}
</script>

