Dashboards & Visualizations

Why do I get the previously inserted value when using JavaScript to read an input value?

andrewtrobec
Motivator

Hello,

I have a dashboard with a text input that has id "text_input".  With JavaScript I am listening to changes to that input, and when that happens I just want to read the new value into a variable.  Instead of reading the newly inserted value, though, it reads the previous value.  The following code gives an idea of what I am doing:

 

var def_tok = mvc.Components.get("default");
var sub_tok = mvc.Components.get("submitted");

...

$("#text_input").on('change', function () { 

	console.log("Change Detected");
	
	var sub_tok_input = sub_tok.get("text_input");
	var sub_tok_input_form = sub_tok.get("form.text_input");
	var def_tok_input = def_tok.get("text_input");
	var def_tok_input_form = def_tok.get("form.text_input");
	
	console.log("sub_tok_input: " + sub_tok_input);
	console.log("sub_tok_input_form: " + sub_tok_input_form);
	console.log("def_tok_input: " + def_tok_input);
	console.log("def_tok_input_form: " + def_tok_input_form);

});

 


When I fill in the first value from blank the first print reads blank instead of the value.  Then when I update the value it reads the first value, and so on...
 
What I am doing wrong and how can I ensure that I get the newly inserted value instead of the previously inserted one?
 
Thanks!

Andrew
Labels (1)
Tags (2)
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...