Make initial capital in a user-supplied control name
<p>I have a function with the name MakeInitialCapital. I want to supply control name as an argument and the text in that control must be converted to Initial Capital.</p>

<p>How to modify this Javascript code:</p>

<pre><code>function MakeInitialCapitalControl(controlName)
{
 TextInControl = getElementByID(controlName).value; 
 return str.toLowerCase().replace(/\b[a-z]/g, cnvrt);
function cnvrt() {
    return arguments[0].toUpperCase();
}
</code></pre>

<p><strong>Edited:</strong></p>

<p>One more thing, if the text already has Intials Capital, make it lowercase.</p>
