简体   繁体   English

更改选项长度后,将选项选择为默认

[英]select option to default after changed the option length

I got two radio button that are yes and no , so if i click on yes the tr of div1 that is radio button of dealer and consumer will show from hide, whereas if i click on no it will not show up the two radio button as i just mention. 我有两个单选按钮,分别是“是”和“否” ,因此,如果单击“是,则div1tr经销商和消费者的单选按钮将从隐藏中显示 ,而如果单击“否”,则它不会显示两个单选按钮,我刚才提到。

So now the condition is when i click on yes and click on dealer radio button the select option of CATEGORY have to change to different value as i coded in function override of javascript and also different value if i click on consumer radio button. 所以现在的条件是,当我单击“是”并单击经销商单选按钮时 ,CATEGORY选择选项必须更改为我在javascript 函数覆盖中编码的不同值 ,并且如果我单击消费者单选按钮也将更改为不同的值

BUT if i click on No radio button i wanted to set the CATEGORY select option to default value as i coded in vbscript. 但是,如果我单击“否”单选按钮,类别选择选项设置为我在vbscript中编码的默认值

Let's say i clicked yes and consumer radio button the onchange function change the option length to 1 so after that if i click back on No radio button ,the select option CANNOT change back to the default value anymore. 假设我单击了“是”,并且消费者单选按钮的onchange函数将选项长度更改为1,因此在此之后,如果我单击“否”单选按钮 ,则选择选项将无法再更改回 默认值

Any solutions for this? 有什么解决办法吗? Hope help and thank you. 希望对您有所帮助,谢谢。

<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
%>  

Try placing a 尝试放置一个

list.selectedIndex=0;

where you want the list to return to default. 您希望列表返回默认位置的位置。 The index is 0 based so the first element is 0 not 1. 1 is the second element. 索引基于0,因此第一个元素是0而不是1。1是第二个元素。 You can change 0 to -1 (negative one) if you want the list to select nothing. 如果您希望列表什么都不选择,则可以将0更改为-1(负1)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM