title: How to dynamically find ClientIDs of controls using javascript?
body: <p>I'm working on a javascript function which takes in the names of three controls, then find them on the page.  There are five sets of these controls.  For simplicity, I would like to use the same function and pass in the set of control names, then have the function dynamically find the controls by clientID. Is there a way to do this?</p>
  
  <p>Here's what I have so far...</p>
  
  <pre><code>        function InsertKeyword(keywordCtrl, subjCtrl, bodyCtrl) {
              var ctrl;
              if (OnSubj) ctrl = $find("&lt;%=" + subjCtrl + ".ClientID%&gt;");
              if (OnBody) ctrl = $find("&lt;%=" + bodyCtrl + ".ClientID%&gt;");
              if (OnSubj == 1 || OnBody == 1) {
                  var selectedIndex = document.getElementById(keywordCtrl).selectedIndex;
                  var selectedText = document.getElementById(keywordCtrl).options[selectedIndex].text;
                  var strSpan = '&lt;u&gt;' + selectedText + '&lt;/u&gt;&amp;nbsp';
                  ctrl.pasteHtml(strSpan);
              }
          }
  </code></pre>
  
  <p>This doesn't work, but it illustrates what I'm trying to do.</p>
  
  <p><strong>How do you dynamically find the ClientIDs of controls using javascript?</strong></p>