When I choose Adjustment on the dropdown I am able to get Value, but when rendering the correct form the Dropdown UI in the form does not have the correct Value. It almost works, but I feel I am not doing the jquery correctly. In the View I have 2 different forms, I use the Jquery to select which form I want to show based on the Dropdown Selection.
HERES THE JQUERY
$(document).ready(function() {
$("#adjustments").hide();
$(".TypeClass").change(function() {
var selected = $(".TypeClass option:selected").text();
alert(selected);
if (selected == "Received") {
$("#received").show();
$("#adjustments").hide();
}
if (selected == "Adjustment") {
$("#adjustments").show();
$("#received").hide();
}
});
$(".TypeClass2").change(function() {
var selected = $(".TypeClass2 option:selected").text();
alert(selected);
if (selected == "Received") {
$("#received").show();
$("#adjustments").hide();
}
if (selected == "Adjustment") {
$("#adjustments").show();
$("#received").hide();
}
});
});
HERES THE VIEW
<div id="received">
<fieldset>
<legend>New Inventory Transaction</legend>
<table>
<tr><td>@Html.LabelFor(model => model.ItemName)</td><td>@Html.DisplayFor(model => model.ItemName)</td></tr>
<tr><td>@Html.LabelFor(model => model.ItemNumber)</td><td>@Html.DisplayFor(model => model.ItemNumber)</td></tr>
<tr><td>@Html.LabelFor(model => model.XactTypeId)</td><td>@Html.DropDownListFor(model => model.XactTypeId, (SelectList)ViewData["InvType"], "Choose Type", new { @class = "TypeClass" })</td></tr>
<tr><td>@Html.LabelFor(model => model.XactTotalCost)</td><td>@Html.EditorFor(model => model.XactTotalCost)</td></tr>
<tr><td></td><td><p> <input type="submit" value="Create" /></p></td></tr>
</table>
</fieldset>
</div>
<div id="adjustments">
<fieldset>
<legend>New Inventory Transaction</legend>
<table>
<tr><td>@Html.LabelFor(model => model.ItemName)</td><td>@Html.DisplayFor(model => model.ItemName)</td></tr>
<tr><td>@Html.LabelFor(model => model.ItemNumber)</td><td>@Html.DisplayFor(model => model.ItemNumber)</td></tr>
<tr><td>@Html.LabelFor(model => model.WharehouseName)</td><td>@Html.EditorFor(model => model.WharehouseName)</td></tr>
<tr><td></td><td><p> <input type="submit" value="Create" /></p></td></tr>
</table>
</fieldset>
</div>
to set a drop down list value just use
$(“ddl”).val(“your val”);
and to get the selected value usev
var selectedval = $(“ddl”).val();