Create a string (text) that declares variable and its value, for use in Javascript
<p>I am messing with Javascript code that needs to have variable dynamic part.</p>

<p>I am trying to substitute this piece of Javascript code:</p>

<pre><code>var data = document.getElementById('IDofSomeHiddenField').value;
var print = document.getElementById('IDofOutputField');
print.value = data;
</code></pre>

<p>with something like:</p>

<pre><code>var encapsulatedData = "var data = document.getElementById('IDofSomeHiddenField').value;";
var encapsulatedPrint = "var print = document.getElementById('IDofOutputField');";
</code></pre>

<p>so that when I use somewhere in Javascript code:</p>

<pre><code>encapsulatedData;
encapsulatedPrint;
</code></pre>

<p>this will work:</p>

<pre><code>print.value = data;
</code></pre>

<p>But it does not work.</p>

<p>Is there a way how to declare:</p>

<pre><code>var encapsulatedData
var encapsulatedPrint
</code></pre>

<p>in similar manner like I wrote above, so that:</p>

<pre><code>print.value = data;
</code></pre>

<p>works?</p>
