I have a drop down list that's being generated by ASP.NET MVC3 razor syntax.
<div id="list" style="display:none; float:left;">@Html.DropDownListFor(x => x.PromoType, Model.PromoTypes)</div>
I'm trying to say, "If the second value in the drop down list is picked, make this other drop down list appear"
Given the following javascript, what do I put in place of the question marks? I want to avoid using hard-coded strings.
<script type="text/javascript">
$(function () {
$('#list select').change(function () {
if ($("#list select").val() == ??????????) {
$("#over").show();
$("#product").hide();
}
else if ($("#list select").val() == ??????????) {
$("#product").show();
$("#over").hide();
}
else {
$("#over").hide();
$("#product").hide();
}
});
});
</script>
EDIT The code I ended up using in the if statements was as follows:
$("#list select")[0].selectedIndex == 1
val(). Since you want only the "second item" in the list, useselectedIndexinstead. - Marc B