Rohini Shirke

Rohini Shirke

  • NA
  • 46
  • 31.1k

fire onchange event of dropdownlist on page load

Nov 21 2013 3:29 AM
Hi...
   I have create view in asp.net mvc4.

In my view there is one dropdown:
 @Html.DropDownList("Type", new SelectList(TypeList, "value", "text"), new { id = "ddl1", onchange = "SelectedIndexChanged()" })

In javascript:
   <script type="text/javascript">
        function SelectedIndexChanged() {
            var value = $("#ddl1").val();
            alert(value);
            if (value == "type1")
            {
                document.getElementById('tblsat').style.visibility = "visible";
                document.getElementById('tblSuper').style.visibility = "hidden";
            }
            else
            {
                document.getElementById('tblSuper').style.visibility = "visible";
                document.getElementById('tblsat').style.visibility = "hidden";
            }
        }
    </script>
    At runtime if i change dropdown selection onchange event will work fine..But i want to fire onchange event on page load also.

   Thanks..









Answers (2)