通过选中复选框启用多个输入



我遇到了javascript和表单输入的问题…我有一个由复选框和两个选择列表组成的多个组组成的表单,我需要激活组的选择列表时,他们的复选框被选中…我该怎么办??下面是我的代码:

<input type="checkbox" value="room1" class="bookcheckbox1"><b>Select Room</b>
Adults<select class="bookselect1">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
Children<select class="bookselect1">
<option value="0">0</option>
<option value="1">1</option>
</select>
<input type="checkbox" value="room2" class="bookcheckbox2"><b>Select Room</b>
Adults<select class="bookselect2">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
Children<select class="bookselect2">
<option value="0">0</option>
<option value="1">1</option>
</select>
 <body>
 <script type="text/javascript">
    function able(obj,x){
        if(obj.checked ==true)
            {
                document.getElementById("x"+x).disabled=false;
                document.getElementById("y"+x).disabled=false;
            }
        else
            {
                document.getElementById("x"+x).disabled=true;
                document.getElementById("y"+x).disabled=true;
            }
    }
 </script>
<input type="checkbox" value="room1" class="bookcheckbox1" onchange="able(this,1)"><b>Select Room</b>
Adults<select class="bookselect1" disabled="true" id="x1">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
Children<select class="bookselect1" disabled="true" id="y1">
<option value="0">0</option>
<option value="1">1</option>
</select>
<input type="checkbox" value="room2" class="bookcheckbox2" onchange="able(this,2)"><b>Select Room</b>
Adults<select class="bookselect2" disabled="true" id="x2">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
Children<select class="bookselect2" disabled="true" id="y2">
<option value="0">0</option>
<option value="1">1</option>
</select>
</body> 

相关内容

  • 没有找到相关文章

最新更新