开发者

Changing a select's values based on the value of another select

I have three selects, month, day, and year开发者_JS百科. For this, year is irrelevant. I wrote a script so that on change of the month, it changes the values of the days select so that if they chose 2 as a month, it would change it to only 28 days for february.


please clear all the options before creating a new options.

<script type="text/javascript">
    function pickdata(month){
        day = document.getElementById('day');
        len = day.options.length;
        for(i=len-1;i>=0;i--)
        {
        day.remove(i);
        }
        switch(month){
            case "2":
                max = 30;
            break;
            case "4":
            case "6":
            case "9":
            case "11":
                max = 31
            break;
            case "1":
            case "3":
            case "5":
            case "7":
            case "8":
            case "10":
            case "12":
               max=32;
            break;
        }
         for(i=1;i< max ; i++){
             var elOptNew = document.createElement('option');
            elOptNew.text = i;
            elOptNew.value = i;
            day.appendChild(elOptNew);
        }
    }
</script>

<select name="month" id="month" onchange="pickdata(this.value)">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜