[英]How can I get a DropDownList selected value and send it to the controller in ASP.NET MVC 4 and using JavaScript?
[英]how can i show validation on without selecting dropdownlist value using javascript and asp.net
我有dropdownlist和一个fileupload按钮,当我不选择dropdownlist值时,我想显示错误message.i在javascript中试过代码,但是无论是否选择dropdownlist值,它都会显示错误消息,我仅使用Java脚本来引发错误我尝试的代码消息是:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript" lang="javascript">
$(document).ready(function () {
$('#txtBoxValue').click(function () {
if ($("#ddlsubjname").val() > 0) {
return true;
}
else {
alert('Please select Country')
return false;
}
})
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table align="center"><tr><td>
<asp:DropDownList ID="ddlsubjname" runat="server" >
<asp:ListItem>--Select Items--</asp:ListItem>
<asp:listitem>Apple</asp:listitem>
<asp:listitem>>Mango</asp:listitem>
<asp:listitem>Grapes</asp:listitem>
</asp:DropDownList>
</td></tr>
<tr><td></td></tr>
<tr>
<td>
<span id="txtBoxValue"><asp:FileUpload ID="filuploadmp3" runat="server" /></span>
</td>
<td><asp:Label ID="lblmsg" runat="server" Text=""></asp:Label></td>
</tr>
</table>
谁能帮我吗
我对您的问题的理解...您可以使用此示例来验证您的下拉列表
<asp:DropDownList ID="ddlFruits" runat="server">
<asp:ListItem Text="Please Select" Value=""></asp:ListItem>
<asp:ListItem Text="Mango" Value="1"></asp:ListItem>
<asp:ListItem Text="Apple" Value="2"></asp:ListItem>
<asp:ListItem Text="Orange" Value="3"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnSubmit" Text="Validate" runat="server" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnSubmit]").click(function () {
var ddlFruits = $("[id*=ddlFruits]");
if (ddlFruits.val() == "") {
//If the "Please Select" option is selected display error.
alert("Please select an option!");
return false;
}
return true;
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.