创建一个 JavaScript 函数,读取下拉列表以显示单选按钮

Create a JavaScript function that reads the dropdown list to display a radio button

我有一个包含数据的下拉列表,如果我 select 一个特定的东西,它会显示每小时单选按钮或工资单选按钮,例如,如果我 select 经理,它应该显示工资单选按钮并设置 selected,如果我 select 做饭,应该选中每小时单选按钮。

<select name="ntitle">
   <option selected value="0">&nbsp;</option>
   <%do until rsPositions.eof
        strContent = rsPositions("descrip")
        StrValue   = rtrim(rsPositions("descrip"))
        intThisId = rsPositions("id")
        if ucase(rtrim(strNtitle))=ucase(strValue) then%> 
           <option selected value="<%=strValue%>"><%=StrContent%></option>
        <%else      
          if not StrReadOnly then%>
            <option value="<%=strValue%>"><%=StrContent%></option>
          <%end if  
        end if
        rsPositions.movenext
    loop%>
</select>

单选按钮代码:

if StrNewtype="H" then%>
   <input type="radio" name="newtype" value="H" checked>
<% else%>  
   <input type="radio" name="newtype" value="H">
<% end if%>Hourly&nbsp;&nbsp;
<% if StrNewType="S" then%>
   <input type="radio" name="newtype" value="S" checked>
<% else%>  
   <input type="radio" name="newtype" value="S">
<% end if%>Salary(<%=StrPayCycleDes%>)

在您的经典 ASP 脚本中检索数据时,请根据您的需要进行修改:

function kick1()
{

var e = document.getElementById("post");
var strPost = e.value;

if (strPost=="Cook")
{  
 document.getElementById("TT1").checked=true;
}

if (strPost=="Manager")
{  
document.getElementById('TT2').checked=true;
}

if (strPost=="")
{
document.getElementById('TT1').checked=false;
document.getElementById('TT2').checked=false;

}

}
<select onchange='javascript:kick1();' id=post>
<option value="">Please select
<option value="Manager">Manager
<option value="Cook">Cook
</select>
<br>

<input type=radio name=newtype id=TT1 value='H'>Hourly
<input type=radio name=newtype id=TT2 value='S'>Salary