<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do I add JavaScript to a Splunk dashboard? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-JavaScript-to-a-Splunk-dashboard/m-p/336277#M21790</link>
    <description>&lt;P&gt;Hi splunkers,&lt;/P&gt;

&lt;P&gt;I am using code provided below for adding the code.js in my splunk dashboard.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard script="code.js"&amp;gt;
      &amp;lt;label&amp;gt;html_css_js&amp;lt;/label&amp;gt;
      &amp;lt;row&amp;gt;
        &amp;lt;panel&amp;gt;
          &amp;lt;html&amp;gt;
            &amp;lt;div&amp;gt;
            &amp;lt;p&amp;gt;Click the following button to call the function&amp;lt;/p&amp;gt;

          &amp;lt;form&amp;gt;
             &amp;lt;input type="button" onclick="sayHello()" value="Say Hello"/&amp;gt;
          &amp;lt;/form&amp;gt;

          &amp;lt;p&amp;gt;Use different text in write method and then try...&amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
          &amp;lt;/html&amp;gt;
        &amp;lt;/panel&amp;gt;
      &amp;lt;/row&amp;gt;
    &amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And i have placed the  code.js in /opt/splunk/etc/apps/manish_testing/appserver/static&lt;BR /&gt;
after that restarted splunk &lt;/P&gt;

&lt;P&gt;but still i am not getting the result&lt;/P&gt;

&lt;P&gt;code.js:&lt;BR /&gt;
splunk@manish121:~/etc/apps/manish_testing/appserver/static $ cat code.js&lt;BR /&gt;
function sayHello()&lt;BR /&gt;
         {&lt;BR /&gt;
            document.write ("Hello there!");&lt;BR /&gt;
         }&lt;/P&gt;

&lt;P&gt;Please help :&lt;BR /&gt;
Let me know if i am doing wrong or there is another way to do it. &lt;/P&gt;</description>
    <pubDate>Fri, 27 Oct 2017 11:39:52 GMT</pubDate>
    <dc:creator>kannu</dc:creator>
    <dc:date>2017-10-27T11:39:52Z</dc:date>
    <item>
      <title>How do I add JavaScript to a Splunk dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-JavaScript-to-a-Splunk-dashboard/m-p/336277#M21790</link>
      <description>&lt;P&gt;Hi splunkers,&lt;/P&gt;

&lt;P&gt;I am using code provided below for adding the code.js in my splunk dashboard.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard script="code.js"&amp;gt;
      &amp;lt;label&amp;gt;html_css_js&amp;lt;/label&amp;gt;
      &amp;lt;row&amp;gt;
        &amp;lt;panel&amp;gt;
          &amp;lt;html&amp;gt;
            &amp;lt;div&amp;gt;
            &amp;lt;p&amp;gt;Click the following button to call the function&amp;lt;/p&amp;gt;

          &amp;lt;form&amp;gt;
             &amp;lt;input type="button" onclick="sayHello()" value="Say Hello"/&amp;gt;
          &amp;lt;/form&amp;gt;

          &amp;lt;p&amp;gt;Use different text in write method and then try...&amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
          &amp;lt;/html&amp;gt;
        &amp;lt;/panel&amp;gt;
      &amp;lt;/row&amp;gt;
    &amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And i have placed the  code.js in /opt/splunk/etc/apps/manish_testing/appserver/static&lt;BR /&gt;
after that restarted splunk &lt;/P&gt;

&lt;P&gt;but still i am not getting the result&lt;/P&gt;

&lt;P&gt;code.js:&lt;BR /&gt;
splunk@manish121:~/etc/apps/manish_testing/appserver/static $ cat code.js&lt;BR /&gt;
function sayHello()&lt;BR /&gt;
         {&lt;BR /&gt;
            document.write ("Hello there!");&lt;BR /&gt;
         }&lt;/P&gt;

&lt;P&gt;Please help :&lt;BR /&gt;
Let me know if i am doing wrong or there is another way to do it. &lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 11:39:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-JavaScript-to-a-Splunk-dashboard/m-p/336277#M21790</guid>
      <dc:creator>kannu</dc:creator>
      <dc:date>2017-10-27T11:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add JavaScript to a Splunk dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-JavaScript-to-a-Splunk-dashboard/m-p/336278#M21791</link>
      <description>&lt;P&gt;@kannu, I had answered something on similar lines &lt;A href="https://answers.splunk.com/answers/579537/how-to-use-javascript-code-in-splunk-cloud-dashboa.html"&gt;https://answers.splunk.com/answers/579537/how-to-use-javascript-code-in-splunk-cloud-dashboa.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;You can also refer to some of Simple XML JavaScript extension examples on &lt;CODE&gt;Splunk Dashboard Examples&lt;/CODE&gt; app on Splunkbase ( &lt;CODE&gt;&lt;A href="https://splunkbase.splunk.com/app/1603/" target="test_blank"&gt;https://splunkbase.splunk.com/app/1603/&lt;/A&gt;&lt;/CODE&gt; )&lt;BR /&gt;
Or the Splunk Web Framework tutorial: &lt;A href="http://dev.splunk.com/view/webframework-tutorials/SP-CAAAERB"&gt;http://dev.splunk.com/view/webframework-tutorials/SP-CAAAERB&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 12:54:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-JavaScript-to-a-Splunk-dashboard/m-p/336278#M21791</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-27T12:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add JavaScript to a Splunk dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-JavaScript-to-a-Splunk-dashboard/m-p/336279#M21792</link>
      <description>&lt;P&gt;@niketnilay &lt;BR /&gt;
thank you for very quick answer . &lt;/P&gt;

&lt;P&gt;But same alert i want to trigger by using button for that i have added code in html &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard script="example.js"&amp;gt;
   &amp;lt;label&amp;gt;Hello World JavaScript Example&amp;lt;/label&amp;gt;
   &amp;lt;row&amp;gt;
     &amp;lt;panel&amp;gt;
       &amp;lt;html&amp;gt;
         &amp;lt;div&amp;gt;
           Splunk Simple XML JavaScript Extension to show Hello World alert and console log using JavaScript file &amp;lt;b&amp;gt;hello_world.js&amp;lt;/b&amp;gt;.
           The JavaScrpt File needs to be placed under the Splunk App's Static folder i.e. &amp;lt;b&amp;gt;$SPLUNK_HOME$/apps/etc/$env:app$/appserver/static&amp;lt;/b&amp;gt;, based on the current app &amp;lt;b&amp;gt;$env:app$&amp;lt;/b&amp;gt;.
         &amp;lt;/div&amp;gt;&amp;amp;lt;br/&amp;amp;gt;
         &amp;lt;div&amp;gt;
           Following is the JavaScript Code:&amp;lt;br/&amp;gt;&amp;amp;lt;br/&amp;amp;gt; 
           &amp;lt;form&amp;gt;
              &amp;lt;input type="button" onclick="function()" value="Say Hello"/&amp;gt;
           &amp;lt;/form&amp;gt;
           PS: Press &amp;lt;code&amp;gt;F12&amp;lt;/code&amp;gt; to Open Browser Inspect Tool to view JavaScript console log. 
         &amp;lt;/div&amp;gt;
       &amp;lt;/html&amp;gt;
     &amp;lt;/panel&amp;gt;
   &amp;lt;/row&amp;gt;
 &amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Oct 2017 12:46:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-JavaScript-to-a-Splunk-dashboard/m-p/336279#M21792</guid>
      <dc:creator>kannu</dc:creator>
      <dc:date>2017-10-30T12:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add JavaScript to a Splunk dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-JavaScript-to-a-Splunk-dashboard/m-p/336280#M21793</link>
      <description>&lt;P&gt;js code i am using &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
"splunkjs/mvc",
"splunkjs/mvc/simplexml/ready!"
         ], function(mvc) {
             var myEvents = mvc.Components.get('myevents');
             myEvents.on("click", function(e) {
                         alert("Hello World");
                         console.log("Click!");
                         });
         });
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Oct 2017 13:26:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-JavaScript-to-a-Splunk-dashboard/m-p/336280#M21793</guid>
      <dc:creator>kannu</dc:creator>
      <dc:date>2017-10-30T13:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add JavaScript to a Splunk dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-JavaScript-to-a-Splunk-dashboard/m-p/336281#M21794</link>
      <description>&lt;P&gt;@kannu, In order code the click() event of your custom input button using jQuery selector, try the following two steps:&lt;/P&gt;

&lt;P&gt;1)  Give input an id for example &lt;CODE&gt;id="myHelloButton"&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;input type="button" onclick="function()" value="Say Hello"/&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;2) In the JavaScript code add jQuery selector based on id as &lt;CODE&gt;$("#myHelloButton")&lt;/CODE&gt; and then code the &lt;CODE&gt;click()&lt;/CODE&gt; event&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;     $("#myHelloButton").on("click",function(){
                 alert("Hello World");
                 console.log("Click!");
          });
     });
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There is an example for similar scenario (Refresh Dashboard on Button Click) : &lt;A href="https://answers.splunk.com/answers/554639/i-want-to-refresh-the-dashboard-on-button-click-is.html"&gt;https://answers.splunk.com/answers/554639/i-want-to-refresh-the-dashboard-on-button-click-is.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Please try out and confirm.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 14:10:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-JavaScript-to-a-Splunk-dashboard/m-p/336281#M21794</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-30T14:10:06Z</dc:date>
    </item>
  </channel>
</rss>

