0

This is my JavaScript:

$(document).ready(function () {
    function ShowHelp() {
        window.open('../WebHelp/' + '<%= SessionManager.CurrentDictionaryId %>' + '/mweb.htm#cshelp/assetsdetail.htm', '', 'toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
    }
    function RunPrint(values) {
        window.open('../Reports/Assets/AssetProfile.aspx?id=' + values, '', 'toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
    }
});

And I have two <asp:Hyperlink> tags set like this:

<asp:HyperLink ID="lnkHelp" runat="server" EnableViewState="False" ImageUrl="~/Images/Help.png"
        NavigateUrl="javascript:ShowHelp();" />
<asp:HyperLink ID="lnkPrint" ImageUrl="~/Images/PrintMed.png" runat="server" EnableViewState="false"
        NavigateUrl="javascript:GetSelectedToPrint();" />

When running the debugger tools in Chrome I get the message:

"Uncaught ReferenceError: ShowHelp is not defined"
"(anonymous function)"

I am fairly ignorant in javascript, but I feel like I know enough to read what is there and i don't see the issue.

3
  • Unwrap it from $(document).ready. Commented Jun 20, 2012 at 20:19
  • yup, just tried that and it worked. Any reference you can point me to as to why this happens? Commented Jun 20, 2012 at 20:21
  • It's because you're calling the methods from a javascript: URI, which uses global functions. By nesting the functions in another function, they are no longer global, and can't get called through said URI. Commented Jun 20, 2012 at 20:24

1 Answer 1

1

did you try to remove the $(document).ready(function(){ ?

that code is not needed if you are just wanting to create a function that will be fired after the controls were loaded (which is in your case).

Sign up to request clarification or add additional context in comments.

1 Comment

That worked, I tried it out just as you posted the answer. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.