Dashboards & Visualizations

Why do I have to reload my dashboard to execute a search?

JarrenJ
Explorer

I am using Javascript to dynamically add a hash string to an input from splunk, based on its ID. it updates the value of the input but when i click Submit, it doesnt do anything. I have to refresh the page and then paste in the value for it to work. This defeats the purpose of autofilling the input field based on the file uploaded.

any help would appreciated, thanks!

EDIT:

This is my script:

$(document).ready(function () {
  $("#btn").click(function () {
      var reader = new FileReader(); //define a Reader
      var file = $("#f1")[0].files[0]; //get the File object 
      if (!file) {
          alert("no file selected");
          return;
      } //check if user selected a file

      reader.onload = function (f) {
          var file_result = this.result; // this == reader, get the loaded file "result"
          var file_wordArr = CryptoJS.lib.WordArray.create(file_result); //convert blob to WordArray
          var sha1_hash = CryptoJS.SHA1(file_wordArr); //calculate SHA1 hash
            $('#input1_3520-input').attr('value', sha1_hash);
          //document.getElementById("input1_3520-input").value = sha1_hash; //put hash into input field
          //alert("Calculated SHA1:" + sha1_hash.toString()); //output result
      };
      reader.readAsArrayBuffer(file); //read file as ArrayBuffer
  });
});

It works, it puts the generated hash into my field but to actually run the search, I need to copy the hash, reload the page and then paste it in and it works... I don't think its a timing issue. Could it be that it is only changing the text value of the input field and not that actual value?

EDIT #2:

Now, I don't need to reload the page i just need to actually type a character in the field, hit submit, then delete the added character and hit submit again and it runs the search on the hash... My only guess is that the input field isn't actually detected a value change?

0 Karma

elliotproebstel
Champion

I've seen behavior like this when my javascript had some timing issues. Can you share the dashboard XML and javascript code? Feel free to obfuscate any sensitive data.

0 Karma

JarrenJ
Explorer

thanks for the response guys, see the updated question.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...