Nikhil D
Nikhil D

Reputation: 2509

focus(); not working in mozilla but fine in IE and chrome

    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

Upvotes: 0

Views: 1259

Answers (1)

Ravi Vanapalli
Ravi Vanapalli

Reputation: 9942

Focus() must be setting focus try using your keyboard key Up/ down arrow and check.

Upvotes: 1

Related Questions