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?
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.
thanks for the response guys, see the updated question.