Microsoft JScript runtime error: '(function name)' is undefined

Posted by Velika2 on Stack Overflow See other posts from Stack Overflow or by Velika2
Published on 2010-05-01T04:05:18Z Indexed on 2010/05/01 4:17 UTC
Read the original article Hit count: 361

Filed under:
|

Microsoft JScript runtime error: 'txtGivenName_OnFocus' is undefined

After adding what I thought was unrelated javascript code to a web page, I am suddenly getting errors that suggest that the browser cannot locate a javascript function that, to me, appears plain as day in design mode.

I'm thinking that this is a load sequence order problem of some sort. Originally, my script was at the bottom of the page. I did this with the intent of helping my site's SEO ranking.

When I moved the function to the top of the web page, the error went away. Now it is back.

I have a feeling someone is going to suggest a jQuery solution to execute some code only when the page is fully loaded. I'm I ignorant of jQuery. IfjQuery is given in the answer, please explain what I need to do (references, placement of script files) for VS 2010 RTM.

I am trying to set the focus to the first textbox on the webpage and preselect all of the text in the textbox

More info:

If I disable this Validator, the problem goes away:

<asp:CustomValidator ID="valSpecifyOccupation" runat="server" ErrorMessage="Required"
                                            ClientValidationFunction="txtSpecifyOccupation_ClientValidate" 
                                            Display="Dynamic" Enabled="False"></asp:CustomValidator>



function txtSpecifyOccupation_ClientValidate(source, args) {

    var optOccupationRetired = document.getElementById("<%=optOccupationRetired.ClientID %>");

    if (optOccupationRetired.checked) {
        args.IsValid = true;
    }
    else {
        var txtSpecifyOccupation = document.getElementById("<%=txtSpecifyOccupation.ClientID %>");
        args.IsValid = ValidatorTrim(txtSpecifyOccupation.value) != "";
    }

}

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about VS2010