Abstract: I'm trying to set an error message if a choice has not been made by a drop down menu.
Details:
Here's my dd with a call to a javascript function:
<%:Html.DropDownListFor(r => Model.TypeId, TypeItems, new { @class="stretchInput", @onblur = "errorCheck"})%>
Here's my javascript:
<script type="text/javascript">
$(document).on("blur", "select[name=TypeId]",
function errorCheck() {
var errId = 'Type not chosen. Please choose from the menu.';
if (document.getElementById('TypeId').selectedIndex == 0) {
document.getElementById("DetailsError").visibility = 'visible';
document.getElementById("DetailsError").innerHTML = errId;
}
});
</script>
Here's the label that I want to change the value of:
<td><asp:Label ID="DetailsError" runat="server" CssClass="errorMsg" Text="testing" Visible="false"></asp:Label></td>
I'm aware that it's an ASP control, by the way. I've tried HTML label and get the same result.
All I'm trying to set the label's text with my error message. It appears that nothing I do affects the label in any way.
What am I missing?