Microsoft JScript runtime error: '(function name)' undefined
Microsoft JScript runtime error: 'txtGivenName_OnFocus' undefined
After adding what I thought was unrelated javascript code to a web page, I suddenly get errors that suggest the browser cannot find the javascript function, which seems as simple to me as a day in development mode.
I think this is a load sequence order problem. Initially, my script was at the bottom of the page. I did this with the intention of helping the site's SEO rankings.
When I moved the function to the top of the webpage, the error went away. Now he's back.
I have a feeling that someone would suggest a jQuery solution to execute some code only when the page is fully loaded. I don't know jQuery. IfjQuery is listed in the answer, please explain what I need to do (links, script file placement) for RTM VS 2010.
I am trying to set focus to the first textbox on a webpage and pre-select all text in the textbox
Additional Information:
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) != "";
}
}
Yes, I would say it is most likely a boot problem. And ... I would totally recommend jquery ...
Wherever you call your JavaScript function txtSpecifyOccupation_ClientValidate ; I assume you can dynamically write a script block to the page on load, or whatever ...
if it is true. I would add the following to your generated script block ...
$(function() {
... call to function
txtSpecifyOccupation_ClientValidate();
...
});
jquery is very easy to learn. http://docs.jquery.com/Main_Page
a source to share