locked
Jquery in webresource not being triggered in CRM 2016 RRS feed

  • Question

  • Hi,

    I have a webresource on my opportunity form. In this web resource, I'm trying to call some jquery functions on the click of a button within the web resource. When I open the html web resource page with IE, it works fine, but when I copy the code into the text editor of the web resource, publish it, then go to CRM and click the button, nothing happens. The jquery does not get triggered.

    Any ideas?

    Here's the webresource code:

    <!DOCTYPE html>
    <html>
    <head>
    <style type="text/css">
      body
      {
       font-family: Segoe UI, Tahoma, Arial;
       background-color: white;
      }
      tbody
      {
       background-color: white;
      }
      th
      {
       background-color: black;
       color: White;
      }
     </style>
    <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>-->
    <script type="text/javascript" src="C:\Users\Company\Webresources\scripts\jquery-3.2.1.min.js"></script>
    <script>
    
     $(function(){  
        $("#button1").click(function(){	
    	alert("1");
            $("#list1 > option:selected").each(function(){
    alert("2");		
                $(this).remove().appendTo("#list2");
            });
        });
    
        $("#button2").click(function(){
    	alert("3");
            $("#list2 > option:selected").each(function(){
    		alert("4");
                $(this).remove().appendTo("#list1");
            });
        });
    });​
    
    </script>
    </head>
    <body>
    
    <div>
    <table width=100%>
     <tr>
        <th>Available Accessories</th>
    	<th></th>
        <th>Chosen Accessories</th>
      </tr>
    <tr>
    <td width=40%>    
        <select id="list1" multiple="multiple" rows=2 style="width: 100%; height: 100%;">
            <option value=1>Option 1</option>
            <option value=2>Option 2</option>
            <option value=3>Option 3</option>
            <option value=4>Option 4</option>
        </select>
        <br/>
    </td>
    <td width="20%">
    <table>
    <tr>
        <td width="100%" align="center"><input id="button1" type="button" value=">" /></td>
    </tr>
    <tr>
    	<td width="100%" align="center"><input id="button2" type="button" value="<" /></td>
    </tr>
    </table>
    </td>
    <td width="40%">    
        <select id="list2" multiple="multiple" rows=2 style="width: 100%; height: 100%;">        
        </select>
        <br/>
    </td>
    </tr>
    </table>
    </div>
    
    </body>
    </html>

    None of the alerts are displayed from within CRM.

    Thanks.


    • Edited by MOTO1978 Tuesday, August 29, 2017 3:09 PM
    Tuesday, August 29, 2017 3:07 PM

Answers

  • This was fixed by checking if the document was ready before doing anything else.
    • Marked as answer by MOTO1978 Wednesday, August 30, 2017 4:24 PM
    Wednesday, August 30, 2017 4:24 PM

All replies

  • Hello,

    Don't reference script files located on your hard drive. Try to create those webresources in CRM and reference it in your Html page.

    Good luck.


    Dynamics CRM/Business Solutions MVP
    Read My blog

    Tuesday, August 29, 2017 3:27 PM
    Moderator
  • This was fixed by checking if the document was ready before doing anything else.
    • Marked as answer by MOTO1978 Wednesday, August 30, 2017 4:24 PM
    Wednesday, August 30, 2017 4:24 PM