<?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 to code Javascript into the dashboardcode without loading a js file? in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-code-Javascript-into-the-dashboardcode-without-loading-a/m-p/454822#M55949</link>
    <description>&lt;P&gt;Hello Splunkers,&lt;/P&gt;

&lt;P&gt;I'm trying to code some Javascript into my Splunk simpleXML  dashboard via Edit Dashboard -&amp;gt; Source,&amp;nbsp;to conditionally adjust the colors of the rows in the dashboard. The script works fine in other text editors, but does not seem to load in the Splunk dashboard. Does anybody know how I could get my script to load in the dashboard? The HTML and CSS code I have coded directly in the SimpleXML works fine, it's just the Javascript that won't load.  I have put in the script&amp;nbsp;as follows (this is a shortened version);&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;style&amp;gt;
         .statusError{
            background-color: #D93F3C !important;}
         .statusOk {
            background-color: #65A637 !important;}
         .statusPaused {
            background-color: #DDDDDD !important;}
         &amp;lt;/style&amp;gt;

        &amp;lt;script&amp;gt;
          window.addEventListener("DOMContentLoaded", function() {
  var table = document.getElementById('theTable');
  var tbody = table.getElementsByTagName('tbody')[0];
  rijKleuren(tbody.getElementsByTagName('td'));
}, 
  false);

var rijKleuren = function(cells){
for (var i=0, len=cells.length; i&amp;lt;len; i++){
    if (cells[i].innerHTML == 'ERROR'){
        cells[i].className += '' + 'statusError';
      cells[i].parentNode.className += '' + 'statusError';
    }
    else if (cells[i].innerHTML == 'OK'){
        cells[i].className += '' + 'statusOk';
      cells[i].parentNode.className += '' + 'statusOk';
    }
  else if (cells[i].innerHTML == 'PAUSED'){
        cells[i].className += '' + 'statusPaused';
      cells[i].parentNode.className += '' + 'statusPaused';
    }
 }
        &amp;lt;/script&amp;gt;
      &amp;lt;/html&amp;gt;
      &amp;lt;table id="theTable"&amp;gt;
        &amp;lt;title&amp;gt;Scripts theTable&amp;lt;/title&amp;gt;
etc(rest of table specifications)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Might it be that I have to use a different type of EventListener? Or is it just not possible to incorporate Javascript without a seperate JS file?&lt;/P&gt;</description>
    <pubDate>Fri, 22 Mar 2019 13:58:29 GMT</pubDate>
    <dc:creator>JvKessel</dc:creator>
    <dc:date>2019-03-22T13:58:29Z</dc:date>
    <item>
      <title>How to code Javascript into the dashboardcode without loading a js file?</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-code-Javascript-into-the-dashboardcode-without-loading-a/m-p/454822#M55949</link>
      <description>&lt;P&gt;Hello Splunkers,&lt;/P&gt;

&lt;P&gt;I'm trying to code some Javascript into my Splunk simpleXML  dashboard via Edit Dashboard -&amp;gt; Source,&amp;nbsp;to conditionally adjust the colors of the rows in the dashboard. The script works fine in other text editors, but does not seem to load in the Splunk dashboard. Does anybody know how I could get my script to load in the dashboard? The HTML and CSS code I have coded directly in the SimpleXML works fine, it's just the Javascript that won't load.  I have put in the script&amp;nbsp;as follows (this is a shortened version);&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;style&amp;gt;
         .statusError{
            background-color: #D93F3C !important;}
         .statusOk {
            background-color: #65A637 !important;}
         .statusPaused {
            background-color: #DDDDDD !important;}
         &amp;lt;/style&amp;gt;

        &amp;lt;script&amp;gt;
          window.addEventListener("DOMContentLoaded", function() {
  var table = document.getElementById('theTable');
  var tbody = table.getElementsByTagName('tbody')[0];
  rijKleuren(tbody.getElementsByTagName('td'));
}, 
  false);

var rijKleuren = function(cells){
for (var i=0, len=cells.length; i&amp;lt;len; i++){
    if (cells[i].innerHTML == 'ERROR'){
        cells[i].className += '' + 'statusError';
      cells[i].parentNode.className += '' + 'statusError';
    }
    else if (cells[i].innerHTML == 'OK'){
        cells[i].className += '' + 'statusOk';
      cells[i].parentNode.className += '' + 'statusOk';
    }
  else if (cells[i].innerHTML == 'PAUSED'){
        cells[i].className += '' + 'statusPaused';
      cells[i].parentNode.className += '' + 'statusPaused';
    }
 }
        &amp;lt;/script&amp;gt;
      &amp;lt;/html&amp;gt;
      &amp;lt;table id="theTable"&amp;gt;
        &amp;lt;title&amp;gt;Scripts theTable&amp;lt;/title&amp;gt;
etc(rest of table specifications)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Might it be that I have to use a different type of EventListener? Or is it just not possible to incorporate Javascript without a seperate JS file?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 13:58:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/How-to-code-Javascript-into-the-dashboardcode-without-loading-a/m-p/454822#M55949</guid>
      <dc:creator>JvKessel</dc:creator>
      <dc:date>2019-03-22T13:58:29Z</dc:date>
    </item>
  </channel>
</rss>

