I am trying to implement a feature where a div is displayed on the onchange
event of a dropdownlist using JavaScript, but I keep getting an error message saying object required
Here is the ASPX code snippet:
<asp:DropDownList runat="server" ID="lstFilePrefix1" onchange="showTR();" >
<asp:ListItem Text="Prefix1" Value="Prefix1" />
<asp:ListItem Text="Prefix2" Value="Prefix2" />
<asp:ListItem Text="Prefix3" Value="Prefix3" />
<asp:ListItem Text="Prefix1 and Prefix2" Value="Prefix1 and Prefix2" />
<asp:ListItem Text="Prefix2 and Prefix3" Value="Prefix2 and Prefix3" />
</asp:DropDownList>
And here is the relevant JavaScript code inside a .js file:
function showTR() {
var dropdown = document.getElementById( "<%=lstFilePrefix1.ClientID%>" );
var selectedItemValue = dropdown.options[ dropdown.selectedIndex ].value;
var div2 = document.getElementById( "data" );
if( selectedItemValue == 'Prefix2' ) {
div2.style.dispaly= "block";
} else {
div2.style.display = "none";
}
}