<?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 Re: Why is my javascript function not executing in my dashboard? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252717#M15743</link>
    <description>&lt;P&gt;Makes sense. Do I have to restart the Splunk server to reflect changes if I move/modify the .js file? Would inline JS be better?&lt;/P&gt;</description>
    <pubDate>Wed, 25 Jan 2017 00:03:48 GMT</pubDate>
    <dc:creator>tmontney</dc:creator>
    <dc:date>2017-01-25T00:03:48Z</dc:date>
    <item>
      <title>Why is my javascript function not executing in my dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252712#M15738</link>
      <description>&lt;P&gt;Branching off my last question, I now cannot get this function to load on button click. Works fine in a local html file.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard&amp;gt;
  &amp;lt;label&amp;gt;test&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
               &amp;lt;div id="frm" style="width:  300px; height: 100px; float: left;"&amp;gt;
                 &amp;lt;form script="users.js"&amp;gt;
         Usernames (separate by comma): &amp;lt;input type="text" id="uname"/&amp;gt;
         &amp;lt;input id="unameSubmit" type="button" value="Submit" onclick="httpPost('http://www.example.com')"/&amp;gt;
         &amp;lt;/form&amp;gt;
         &amp;lt;/div&amp;gt;
       &amp;lt;div id="main" style="width: 400px; height: 300px; float:left;"&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;This time I separated my .js file.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;         function httpPost(theUrl)
{
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4)
        {
        if (xmlhttp.status==200)
        {
            writetobody(xmlhttp.responseText);
            }
        }
    }
    var unameVal = document.getElementById("uname").value;
    var newUrl = theUrl.replace("REPLACEME", unameVal);
    xmlhttp.open("GET", newUrl, true );
    xmlhttp.send(); 
}
            function writetobody(data) {
            if (data!=null) {
            var json = JSON.parse(data);
            for (i = 0; json.length &amp;gt; i; i++) {
            var val1 = json[i]["val1"];
            var val2 = json[i]["val2"];
                        document.getElementById('main').innerText=("\r\nval1: " + val1 + "\r\nval2" + val2);
            }

            }
            }
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jan 2017 23:26:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252712#M15738</guid>
      <dc:creator>tmontney</dc:creator>
      <dc:date>2017-01-24T23:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my javascript function not executing in my dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252713#M15739</link>
      <description>&lt;P&gt;well, if you look at what you posted and notice the green text, it indicates what is in "quotes" of some kind.  &lt;/P&gt;

&lt;P&gt;Looks like the .JS file has a problem in this line -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; var val1 = json[i]["val1];
 var val2 = json[i]["val2"];
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which  probably should read&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; var val1 = json[i]["val1"];
 var val2 = json[i]["val2"];
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jan 2017 23:40:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252713#M15739</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-01-24T23:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my javascript function not executing in my dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252714#M15740</link>
      <description>&lt;P&gt;Sorry, that was an error on me posting. With quotes fixed, it still doesn't work.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 23:42:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252714#M15740</guid>
      <dc:creator>tmontney</dc:creator>
      <dc:date>2017-01-24T23:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my javascript function not executing in my dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252715#M15741</link>
      <description>&lt;P&gt;Even still, it would send a GET request first. I have a breakpoint set on the server side and I see no traffic. That and Chrome doesn't show any HTTP requests.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 23:44:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252715#M15741</guid>
      <dc:creator>tmontney</dc:creator>
      <dc:date>2017-01-24T23:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my javascript function not executing in my dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252716#M15742</link>
      <description>&lt;P&gt;What your trying to do is use Simple XML extensions and my understanding Splunk's Simple XML &lt;STRONG&gt;html&lt;/STRONG&gt; does not support &lt;STRONG&gt;script&lt;/STRONG&gt; tags.  For scripts to work you must embed your script in the parent/root tag which is &lt;STRONG&gt;dashboard&lt;/STRONG&gt; or &lt;STRONG&gt;form&lt;/STRONG&gt;.  If you are using HTML dashboards you can use the &lt;STRONG&gt;script&lt;/STRONG&gt; tag using  relative path of your script.&lt;/P&gt;

&lt;P&gt;example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form script="users.js"&amp;gt;
OR 
&amp;lt;dashboard script="users.js"&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The script must be within the same app context as the view/ dashboard. For more information please read &lt;A href="http://dev.splunk.com/view/webframework-developapps/SP-CAAAE4A"&gt;Modify dashboards using Simple XML extensions&lt;BR /&gt;
&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 23:50:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252716#M15742</guid>
      <dc:creator>bmacias84</dc:creator>
      <dc:date>2017-01-24T23:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my javascript function not executing in my dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252717#M15743</link>
      <description>&lt;P&gt;Makes sense. Do I have to restart the Splunk server to reflect changes if I move/modify the .js file? Would inline JS be better?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 00:03:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252717#M15743</guid>
      <dc:creator>tmontney</dc:creator>
      <dc:date>2017-01-25T00:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my javascript function not executing in my dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252718#M15744</link>
      <description>&lt;P&gt;Moved the .js file to the same folder as the .xml dashboard file. Tried both form script and dashboard script to no avail. Even restarted the splunk server.&lt;/P&gt;

&lt;P&gt;I also created a new dashboard for just this example.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 00:08:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252718#M15744</guid>
      <dc:creator>tmontney</dc:creator>
      <dc:date>2017-01-25T00:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my javascript function not executing in my dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252719#M15745</link>
      <description>&lt;P&gt;If you move the js file, yes.  Modifying technically no, but if this is production you probably have js caching turning on in your web/server config.  You can use the bump url and/ or debug URL to clear force Splunk to recognize the modified script.  I have other post scattered about on answer about those topics.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 00:10:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252719#M15745</guid>
      <dc:creator>bmacias84</dc:creator>
      <dc:date>2017-01-25T00:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my javascript function not executing in my dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252720#M15746</link>
      <description>&lt;P&gt;Please read &lt;A href="http://dev.splunk.com/view/webframework-developapps/SP-CAAAE4A"&gt;Modify dashboards using Simple XML extensions&lt;BR /&gt;
&lt;/A&gt; which will answer your question on why the way you are doing it does not work.  File have to placed in specific directories.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 00:16:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252720#M15746</guid>
      <dc:creator>bmacias84</dc:creator>
      <dc:date>2017-01-25T00:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my javascript function not executing in my dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252721#M15747</link>
      <description>&lt;P&gt;That's me, nit-picker extraordinaire.  Heh.&lt;/P&gt;

&lt;P&gt;Sounds like you have something going, so I'll lurk until you say whether it worked.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 00:16:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252721#M15747</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-01-25T00:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my javascript function not executing in my dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252722#M15748</link>
      <description>&lt;P&gt;Lol, you wouldn't know though. I should have double checked my post. As of right now, nothing's worked so far. Oddly enough when I was first trying this, it &lt;STRONG&gt;was working&lt;/STRONG&gt;. But now I have no clue what's changed.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 14:30:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252722#M15748</guid>
      <dc:creator>tmontney</dc:creator>
      <dc:date>2017-01-25T14:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my javascript function not executing in my dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252723#M15749</link>
      <description>&lt;P&gt;I can confirm now the dashboard sees the script. When hitting edit, it references a custom script. Monitoring network traffic (via browser debug tools), I can see a "200 OK" for my .js file. I can also even browse to the path. Still, the function is not being executed.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 15:28:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-my-javascript-function-not-executing-in-my-dashboard/m-p/252723#M15749</guid>
      <dc:creator>tmontney</dc:creator>
      <dc:date>2017-01-25T15:28:48Z</dc:date>
    </item>
  </channel>
</rss>

