<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: fill textarea from a file in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176578#M186714</link>
    <description>&lt;P&gt;I think your whole issue is that you are attempting to point to a file that is on the filesystem. it must be able to be retrieved via web for this to work.. such as a URL to the text file.&lt;/P&gt;</description>
    <pubDate>Mon, 10 Mar 2014 16:04:34 GMT</pubDate>
    <dc:creator>aelliott</dc:creator>
    <dc:date>2014-03-10T16:04:34Z</dc:date>
    <item>
      <title>fill textarea from a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176570#M186706</link>
      <description>&lt;P&gt;Hello Everyone,&lt;BR /&gt;
Please suggest how I can fill textarea box from a file located in local drive .&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 06 Mar 2014 16:49:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176570#M186706</guid>
      <dc:creator>vikas_gopal</dc:creator>
      <dc:date>2014-03-06T16:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: fill textarea from a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176571#M186707</link>
      <description>&lt;P&gt;One way to do this is to create a custom splunkd endpoint that would retrieve the file data and return it's contents by request. Then have your Mako template or Javascript call it and populate the textbox with returned data.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Mar 2014 00:01:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176571#M186707</guid>
      <dc:creator>Leo</dc:creator>
      <dc:date>2014-03-07T00:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: fill textarea from a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176572#M186708</link>
      <description>&lt;P&gt;If you are using Splunk 6 or the Web Framework, you can convert a dashboard to HTML and read a local file using HTML5/JavaScript.&lt;/P&gt;

&lt;P&gt;To select the file, put &lt;CODE&gt;&amp;lt;input type="file" id="localFileInput"&amp;gt;&lt;/CODE&gt; in the HTML wherever you want the file selection box to be.  Then, add some JavaScript just before the closing script tag in your dashboard that handles the contents of the file.  You'll need to include something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var control = document.getElementById("localFileInput")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;add an event listener:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;control.addEventListener("change", function(event){...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and inside that function you can use &lt;CODE&gt;FileReader()&lt;/CODE&gt; to read the contents of the local file.&lt;/P&gt;

&lt;P&gt;EDITED RESPONSE BELOW:&lt;/P&gt;

&lt;P&gt;Assuming the user will be selecting the file, try the following:&lt;/P&gt;

&lt;P&gt;Select the local file:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;input type="file" id="inputfile"/&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A blank textarea that will be populated by the contents of your text file:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;textarea rows="4" cols="50" id="putcontentshere"&amp;gt;&amp;lt;/textarea&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The javascript needed to put the contents of the file in the textarea (this goes just above the closing script tag in the body of the html):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;//External data file handling starts here
var control = document.getElementById("inputfile"); 
    control.addEventListener("change", function(event){ 
        var reader = new FileReader();      
        reader.onload = function(event){
            var contents = event.target.result;     
            document.getElementById('putcontentshere').value = contents;            
        };      
        reader.onerror = function(event){
            console.error("File could not be read! Code " + event.target.error.code);
        };      
        console.log("Filename: " + control.files[0].name);
        reader.readAsText(control.files[0]);        
    }, false);
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Simple as that.  If you want to do it without the user selecting the file, I think you might be out of luck.  Allowing the browser/DOM to access the local file system &lt;STRONG&gt;without user interaction&lt;/STRONG&gt; would be a big no-no and isn't allowed (that I know of) without hacking something.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Mar 2014 05:52:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176572#M186708</guid>
      <dc:creator>gauldridge</dc:creator>
      <dc:date>2014-03-07T05:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: fill textarea from a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176573#M186709</link>
      <description>&lt;P&gt;@gauldridge Thanks for the reply ,&lt;BR /&gt;
Unfortunately I am new to javascript and  splunk.I found one solution on the following site but it did not work for me.&lt;BR /&gt;
&lt;A href="http://www.sitepoint.com/forums/showthread.php?456093-Read-from-file-then-populate-textarea-with-content"&gt;http://www.sitepoint.com/forums/showthread.php?456093-Read-from-file-then-populate-textarea-with-content&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2014 12:06:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176573#M186709</guid>
      <dc:creator>vikas_gopal</dc:creator>
      <dc:date>2014-03-10T12:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: fill textarea from a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176574#M186710</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/15547407/javascript-read-text-file-using-ajax"&gt;http://stackoverflow.com/questions/15547407/javascript-read-text-file-using-ajax&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2014 13:52:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176574#M186710</guid>
      <dc:creator>aelliott</dc:creator>
      <dc:date>2014-03-10T13:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: fill textarea from a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176575#M186711</link>
      <description>&lt;P&gt;@aelliott thanks for the reply.&lt;BR /&gt;
I tried it as it mentioned in the link.I copied it and paste it in my javascript file .I changd the path accordingly .Now in splunk where I can call this function?so that it picks up the value and shows it to textarea.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2014 15:06:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176575#M186711</guid>
      <dc:creator>vikas_gopal</dc:creator>
      <dc:date>2014-03-10T15:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: fill textarea from a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176576#M186712</link>
      <description>&lt;P&gt;you could just add it within your script after it is defined. Just add loadXMLDoc() after the code&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2014 15:08:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176576#M186712</guid>
      <dc:creator>aelliott</dc:creator>
      <dc:date>2014-03-10T15:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: fill textarea from a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176577#M186713</link>
      <description>&lt;P&gt;@aelliott I did it but no luck yet.I have added the function after the code.Here is my js code.&lt;BR /&gt;
require(['jquery','underscore','splunkjs/mvc','splunkjs/mvc/simplexml/ready!'], function($, _, mvc, SimpleSplunkView){&lt;BR /&gt;
var content  ;&lt;BR /&gt;
function loadXMLDoc();&lt;BR /&gt;
{&lt;BR /&gt;&lt;BR /&gt;
var textfile;&lt;BR /&gt;
if (window.XMLHttpRequest);&lt;BR /&gt;
{ &lt;BR /&gt;
textfile = new XMLHttpRequest(); &lt;BR /&gt;
}&lt;BR /&gt;
textfile.onreadystatechange = function ();&lt;BR /&gt;
{&lt;BR /&gt;&lt;BR /&gt;
if (textfile.readyState == 4 &amp;amp;&amp;amp; textfile.status == 200)    { &lt;BR /&gt;
content = textfile.responseText; &lt;BR /&gt;
 }&lt;BR /&gt;
  } textfile.open("GET", "D:\vikas\vikas.txt", true);&lt;BR /&gt;
  textfile.send();&lt;BR /&gt;
}&lt;BR /&gt;
});&lt;BR /&gt;
loadXMLDoc();&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2014 16:02:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176577#M186713</guid>
      <dc:creator>vikas_gopal</dc:creator>
      <dc:date>2014-03-10T16:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: fill textarea from a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176578#M186714</link>
      <description>&lt;P&gt;I think your whole issue is that you are attempting to point to a file that is on the filesystem. it must be able to be retrieved via web for this to work.. such as a URL to the text file.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2014 16:04:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176578#M186714</guid>
      <dc:creator>aelliott</dc:creator>
      <dc:date>2014-03-10T16:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: fill textarea from a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176579#M186715</link>
      <description>&lt;P&gt;@vikas_gopal Please see my updated/edited response above.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2014 05:54:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176579#M186715</guid>
      <dc:creator>gauldridge</dc:creator>
      <dc:date>2014-03-11T05:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: fill textarea from a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176580#M186716</link>
      <description>&lt;P&gt;@gauldridge Thanks it works , thanks allot..&lt;BR /&gt;
But as you suggest it is not possible without user interaction actually I don't want to show choose file button .&lt;BR /&gt;
Anyways because of you I achieved this for that thanks again you are awesome...:)&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2014 17:43:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/fill-textarea-from-a-file/m-p/176580#M186716</guid>
      <dc:creator>vikas_gopal</dc:creator>
      <dc:date>2014-03-12T17:43:36Z</dc:date>
    </item>
  </channel>
</rss>

