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?
Here's what I have so far...
function InsertKeyword(keywordCtrl, subjCtrl, bodyCtrl) {
var ctrl;
if (OnSubj) ctrl = $find("<%=" + subjCtrl + ".ClientID%>");
if (OnBody) ctrl = $find("<%=" + bodyCtrl + ".ClientID%>");
if (OnSubj == 1 || OnBody == 1) {
var selectedIndex = document.getElementById(keywordCtrl).selectedIndex;
var selectedText = document.getElementById(keywordCtrl).options[selectedIndex].text;
var strSpan = '<u>' + selectedText + '</u> ';
ctrl.pasteHtml(strSpan);
}
}
This doesn't work, but it illustrates what I'm trying to do.
How do you dynamically find the ClientIDs of controls using javascript?
<%= %>is a server side command