Sdot2323
Sdot2323

Reputation: 59

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

I have a dropdown list with data in it where if I select a particular thing it displays the hourly radio button or salary radio button for example if I select Manager it should display the salary radio button and have it selected, and if I select cook it should have the hourly radio button checked.

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

Radio buttons code:

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

Upvotes: 0

Views: 61

Answers (1)

Ken Lee
Ken Lee

Reputation: 8073

Please modify to suit your need when you retrieve data in your classic ASP script:

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

Upvotes: 1

Related Questions