All Apps and Add-ons

Simple XML strips onclick from HTML button

fk319
Builder

I am trying to do an onclick in a button in an HTML block in Simple XML:

<code>
<dashboard>
  <label>Test Button onclick error</label>
  <row>
    <panel>
      <html>
        <div>
          <button id="button" onclick="myfunction()" rover="dog">Click Here</button>
        </div>
      </html>
    </panel>
  </row>
</dashboard>
</code>

When it gets rendered, onclick is removed. Noticed I added a bogus tag and it was passed through.

<code>
    <div id="row1" class="dashboard-row dashboard-row1">
        <div id="panel1" class="dashboard-cell" style="width: 100%;">
            <div class="dashboard-panel clearfix">

                <div class="panel-element-row">
                    <div id="element1" class="dashboard-element html" style="width: 100%">
                        <div class="panel-body html">
                                <div><button id="button" rover="dog">Click Here</button></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</code>

I am trying to execute a java script on demand from a link in an HTML panel.

Any ideas?

rlacher1
Explorer

Try removing the Bootstrip div elements wrapping your submit button, replacing with a plain div, and sourcing your JavaScript from a .js file -- I was using

<div class="control-group">
    <div class="controls">
        <input id="submit_button" type="button" value="Click" onclick="alert('Test')" />
    </div>
</div>

and replaced it with

dashboard.xml

<input id="submit_button" type="button" value="Click"/>

dashboard.js

require([ "jquery", "splunkjs/mvc/simplexml/ready!"],
         function($){
            $("#submit_button").on("click", function (){
                 alert("Test");
            });
         });

I'm not sure why SimpleXML chomps the onclick, but this workaround helped.

Source: https://answers.splunk.com/answers/378289/calling-java-script-from-dashboard.html

0 Karma

jossplacencia
New Member

this is not working with default submit button (field set) , any suggestions?

0 Karma

fk319
Builder

rlacher1
Explorer

@fk319 try removing any Bootstrap divs surrounding the input -- that was what fixed my issue while using your first link.

0 Karma
Get Updates on the Splunk Community!

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...