Moving inline code into function, with object name generation
<p>I am customizing Denis Gritcyuk's <a href="http://javascriptkit.com/script/script2/timestamp.shtml" rel="nofollow">Popup date picker</a>.</p>

<ol>
<li><p>This pop-up script uses inline Javascript in a <code>href</code> link, to set the selected date into the <code>input</code> field, in the parent window, that is was called for. An example URL looks like:</p>

<pre><code>&lt;a href="javascript:window.opener.document.formname.field.value='03-10-2011';
         window.close();"&gt;3&lt;/a&gt;
</code></pre></li>
<li><p>The input field name, (e.g. <code>document.formname.field</code>), is passed to the script as a string parameter.</p></li>
</ol>

<p>I would like to add things done when that link is clicked (e.g. change background color of field, set flag, etc.). So while this DOES work, it's getting <strong>ugly</strong> fast.</p>

<pre><code>&lt;a href="javascript:window.opener.document.formname.field.value='03-10-2011';
         window.opener.document.formname.field.style.backgroundColor='#FFB6C1'; 
         window.close();"&gt;3&lt;/a&gt;
</code></pre>

<p><br>
How would I move these inline commands into a JS function? This would give me much cleaner URLs and code. The URL would now look something like </p>

<pre><code>&lt;a href="javascript:updateField ('document.formname.field', '03-10-2011');"&gt;3&lt;/a&gt;
</code></pre>

<p>with a function like (this example obviously does NOT work):</p>

<pre><code>function updateField (str_target, str_datetime) {
    var fieldName = "window.opener" + str_target;
    [fieldName].value = str_datetime;
    [fieldName].style.backgroundColor = '#FFB6C1';
    // Set flag, etc.
    window.close();
}
</code></pre>

<p><br>So any suggestions on how this can be done, please?</p>
