InnaS InnaS - 5 months ago 56
ASP.NET (C#) Question

call javascript function on asp dropdown list change

<script type="text/javascript">
function ddl(id) {
// var id = document.getElementById('<%=DDLquestionType.ClientID%>').value;
if (id == "Open") { = 'none';
document.getElementById('Answer1_Btn').style.visibility = false;


<asp:DropDownList ID="DDLquestionType" CssClass="ddlQuestionType box" runat="server" AutoPostBack="True" onchange="ddl(this)" >
<asp:ListItem Text="American" Value="American"></asp:ListItem>
<asp:ListItem Text="Open" Value="Open"></asp:ListItem>
<asp:ListItem Text="Yes/No" Value="YesNo"></asp:ListItem>
<asp:ListItem Text="Numerical" Value="Numerical"></asp:ListItem>

I have this java script function:

Which I try to call on drop down list selection change

It doesn't work.
I also tried
onchange="javascript:ddl()" and function without parameters,
and many others.
I'm new to java script, any links with explanations also will be highly appreciated


you dosent need to pass this parameter or id, you just call the function and onchange() event call the function. in javascript use id of your dropdown list to get the value of dropdown list.

<script type="text/javascript">
function processchange(value)
    // your code

<dropdownlist id="ddl" onchange="processchange()" >
  //enter your dropdown items