Search code examples
javascripthtmlbuttondynamics-crm-2015

Dynamics CRM 2015: How do I get a Web Resource button I created to reference a function in a Javascript Library I added to the form?


I have a button I put onto the form with the code

<button type="button" onclick="btnCalculate_onClick();">test</button>

And I have a function called btnCalculate_onClick() inside a Library I added to the form with the name dc_btnAutofillAddress. The function uses jQuery, but I also have a jQuery library added to the form.

How would I make it so if I click the button, it calls the btnCalculate_onClick() function when it's clicked? I tried the code below and it doesn't work.

<html>
  <head>
    <script type="text/jscript" src="dc_btnAutofillAddress"></script>
  </head>
  <body style="word-wrap: break-word;">
    <button type="button" onclick="btnCalculate_onClick();">test</button>
  </body>
</html>

Solution

  • From a web resource, you can reference the form by doing using window.parent. So:

    <button type="button" onclick="parent.btnCalculate_onClick();">test</button>
    

    Just make sure that, in the form editor, the web resource's option to "Restrict cross-frame scripting" is unchecked.