Init function from serverside html onclick function invalid reference due to scope

Init function from serverside html onclick function invalid reference due to scope

toomanyloginstoomanylogins Posts: 5Questions: 2Answers: 0
edited June 12 in General

I am rendering html serverside

<a href="#" onclick="checkBal('269C9607C92FE045B3A121CEE3F17FD6');">PINV</a>

the page is loaded via ajax and includes a script inline with datatable loaded after document ready. I have tried the checkBal function in intiComplete, after $document Ready and before ready in the script tag. The table loads ok with all rows correct inc urls. However onclick error Uncaught ReferenceError: checkBal is not defined I realise this is something to do with scope so where do I define the function ?

Thanks

Answers

  • kthorngrenkthorngren Posts: 20,796Questions: 26Answers: 4,862
    edited June 12

    Its hard to say why you are getting the error and where to place checkBal() without seeing your solution. I copied you code snippet and created a checkBal() function in this test case and it works:
    https://live.datatables.net/jujihito/1/edit

    something to do with scope so where do I define the function ?

    If this is the case then follow normal Javascript scoping rules to place the function. Datatables doesn't control or affect this.

    Can you post a link to your page or test case replicating the error so wwe can offer suggestions?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • toomanyloginstoomanylogins Posts: 5Questions: 2Answers: 0

    Thanks for reply I resolved it by

    document.checkBal=function checkBal(purchaseID) {.......

    The problem is that the table is populated after an ajax request and for some reason checkBal is no longer in the block scope after the request.

Sign In or Register to comment.