我有两个单选按钮,是和否,所以如果我点击是 tr of div1 经销商和消费者的单选按钮将隐藏显示,而如果我点击否,它将不显示我刚才提到的按钮。
所以现在条件是当我点击是并点击经销商单选按钮
但如果我点击没有单选按钮我想要将 CATEGORY选项选项设置为默认值,就像我在vbscript中编码一样。< / p>
假设我点击是和消费者单选按钮 onchange功能将选项长度更改为1 所以如果我点击后面没有单选按钮< / strong>,选择选项不能再改回到默认值。
任何解决方案?希望有帮助,谢谢。
<script language="Javascript">
function Override(value){
var list = document.getElementById("selCATE");
if (value == "1"){
document.getElementById('selCATE').options.length = 1;
list.add(new Option("Gift to consumers without proof of package sales","Gift to consumers without proof of package sales"));
list.add(new Option("Gift to consumers without proof of package sales","Gift to consumers without proof of package sales"));
}else if (value == "2"){
document.getElementById('selCATE').options.length = 1;
list.add(new Option("Gift to dealers","Gift to dealers"));
}
}
</script>
<input name="rdoGFLG" type="radio" value="Y" onchange=""/>Yes
<input name="rdoGFLG" type="radio" value="N" onchange="Override(this.value)"/>No
<tr id="div1">
<td>
<input name="rdoGTYP" id="rdoGTYP" type="radio" value="1" onchange="Override(this.value);">Consumer
<input name="rdoGTYP" id="rdoGTYP" type="radio" value="2" onchange="Override(this.value);">Dealer
</td>
</tr>
<td valign="top"><b>Category</b></td>
<td valign="top">:</td>
<%
objADO.openRecordSet
strSQL = "SELECT catc from cogstc a where cono='" & SQLEncode(StrCono) & "' and acti=1 order by posi "
Set objRS= objADO.runQuery(StrSQL)
if objRS.recordCount > 0 then
Response.write "<td valign='top' align='left' width='50%'><select name='selCATE' class='NormalInputTextField'>"
Response.write "<option value=''>Select One</option>"
Do until objRS.EOF
Response.write "<option value='" & objRS("catc") & "'>" & objRS("catc") & "</option>"
objRS.MoveNext
loop
Response.write "</select></td>"
end if
%>
答案 0 :(得分:0)
尝试放置
list.selectedIndex=0;
您希望列表返回默认值。索引是基于0的,因此第一个元素是0而不是1. 1是第二个元素。如果希望列表不选择任何内容,可以将0更改为-1(负1)。