On 2/1/06, Laurie Harper <[EMAIL PROTECTED]> wrote:
> Hi, I need to do the equivalent of clicking a commandLink in Javascript;
> in other words, I need to write an onClick handler that does the same
> thing as clicking on a commandLink would. Is there a standard way to do
> that? I'm not sure if the JSF spec includes any specifics on client-side
> APIs.
I have found that it is different for IE vs. Netscape/Firefox. I'm not
a js expert but it works.
This is how I invoke a hidden commandLink in a table row...
<tr onclick="invokeRowLink(this);">
....commandLink
</tr>
function invokeRowLink(row) {
if (navigator.appName.indexOf("Netscape") != -1) {
invokeRowLinkNS(row);
} else {
invokeRowLinkIE(row);
}
}
function doClickNS(anchor) {
var evt = anchor.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('click', false, true,
anchor.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false,
false, 0, null);
anchor.dispatchEvent(evt);
}
function invokeRowLinkNS(row) {
if (row.hasChildNodes) {
tds = row.getElementsByTagName("td");
for(x=0;x<tds.length;x++){
if (tds[x].hasChildNodes) {
childs = tds[x].getElementsByTagName("a");
for(y=0;y<childs.length;y++){
if (childs[y].onclick != null) {
doClickNS(childs[y]);
return;
}
}
}
}
}
}
function invokeRowLinkIE(row) {
if (row.hasChildNodes) {
tds = row.children;
for(x=0;x<tds.length;x++){
if (tds[x].hasChildNodes) {
childs = tds[x].children.tags("A");
for(y=0;y<childs.length;y++){
if (childs[y].onclick != null) {
childs[y].click();
return;
}
}
}
}
}
}