- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi,
I am looking for a sample to set a initial value dynamically using eval or JavaScript.
e.g. set "Monday" or "Tuesday" as a initial value when a form is opened.
I have this very simple form like this:
<form>
<label>sample</label>
<fieldset submitButton="false">
<input type="text" token="a">
<label>Today</label>
<initialValue></initialValue>
</input>
</fieldset>
</form>
and I want to set a value for depending on a day the form is accessed.
I am looking for a way to do this by eval tag or JavaScript extention, but I have not found any sample for this kind of input value initialization.
Any simple sample would be appreciated!
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

You can give the input an id in Simple XML, get that input by its id in your js code and set its default
setting. Should look something like this:
...
type="text" token="a" id="textInput">
<label>Today</label>
...
And in js:
...
var textInput = mvc.Components.get("textInput");
textInput.settings.set("default", "some value or dynamic text");
You can do the same with initialValue, though I doubt you really need that. Docs for that are here.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

You can give the input an id in Simple XML, get that input by its id in your js code and set its default
setting. Should look something like this:
...
type="text" token="a" id="textInput">
<label>Today</label>
...
And in js:
...
var textInput = mvc.Components.get("textInput");
textInput.settings.set("default", "some value or dynamic text");
You can do the same with initialValue, though I doubt you really need that. Docs for that are here.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Thank you! Now I can start adding some more stuff for text box initialization ...
<form script="sample.js">
<label>sample</label>
<fieldset submitButton="false">
<input type="text" token="token1" id="id1">
<label>Text Input</label>
</input>
</fieldset>
</form>
$ cat sample.js
require(["splunkjs/mvc", "splunkjs/mvc/simplexml/ready!"], function(mvc) {
var date1 = new Date();
var year = date1.getFullYear();
var val1 = mvc.Components.get('id1');
val1.settings.set("default", year);
});
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Create a lookup mylookup.csv like below
day_of_w, No
......................
Sunday ,0
Monday ,1
Tuesday ,2
.
.
Saturday,6
|inputlookup mylookup.csv | eval date_wday=strftime(now(),"%w") | eval No=if(date_wday==No,0,No) | sort No | table day_of_w
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Thank you for your input, and I understand what you showed. But could this search result be used for setting initial value for input as a text?
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

You can use a drop down and use
<selectFirstChoice>true</selectFirstChoice>
I'm sure there must be a way to populate text box as well
