function validateForm()
{
var ddlTitle = document.getElementById('<%=ddlTitle.ClientID %>');
if (ddlTitle.value.replace(/^\s+|\s+$/, '').length < 1)
{
alert("Title should not be blank.");
ddlTitle.focus();//not working in mozilla but fine in IE and chrome
return false;
}
}
<asp:DropDownList ID="ddlTitle" runat="server" CssClass="csstextbox">
<asp:ListItem Value="">[Select]</asp:ListItem>
<asp:ListItem>Dr.</asp:ListItem>
<asp:ListItem>Dr.(Mrs.)</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btn" runat="server" CssClass="cssbutton" Text="Save" Width="60px"
OnClientClick="return validateForm();" />
This is HTML source
ddlTitle = document.getElementById('contentPlaceHolderMain_ddlTitle');
function validateForm()
{
if (ddlTitle.value.replace(/^\s+|\s+$/, '').length < 1)
{
alert("Title should not be blank.");
ddlTitle.focus();
return false;
}
}
Problem is only for dropdownlist works well for Textbox
Focus()必须设置焦点,请尝试使用键盘上的上/下箭头并进行检查。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.