Skip to content Skip to sidebar Skip to footer

Javascript Double Click Event

Does anyone know what javascript function I could call to activate the 'dblClickField' event on this id without actually clicking the box? It's a checkbox and I want to force tick

Solution 1:

Don't put so much inline code into your HTML. It's not very easy to read. Put your code in a function, then you can call it whenever you like (without spoofing a double-click event):

<script>functiondblclickfunction(event)
{
    if (window.sfdcPage && window.sfdcPage.hasRun) 
        sfdcPage.dblClickField(event, this);
}
</script><tdclass="dataCol inlineEditWrite"id="00N200000030rph_ilecell"onblur="if (window.sfdcPage && window.sfdcPage.hasRun) sfdcPage.mouseOutField(event, this);"onclick="if (window.sfdcPage && window.sfdcPage.hasRun) sfdcPage.clickField(event, this);"ondblclick="dblclickfunction(event);"onfocus="if (window.sfdcPage && window.sfdcPage.hasRun) sfdcPage.mouseOverField(event, this);"onkeypress="if (window.sfdcPage && window.sfdcPage.hasRun && event && event.keyCode==KEY_ENTER) sfdcPage.dblClickField(event, this);"onmouseout="if (window.sfdcPage && window.sfdcPage.hasRun) sfdcPage.mouseOutField(event, this);"onmouseover="if (window.sfdcPage && window.sfdcPage.hasRun) sfdcPage.mouseOverField(event, this);"tabindex="0"><divid="00N200000030rph_ileinner"><imgsrc="/img/checkbox_unchecked.gif"alt="Not Checked"width="21"height="16"class="checkImg"id="00N200000030rph_chkbox"title="Not Checked"></div></td>

Solution 2:

You can accomplish this by calling apply, as in this answer here:

How can I programmatically invoke an onclick() event from a anchor tag while keeping the ‘this’ reference in the onclick function?

However, you might want to consider a slightly different approach. Just put your double-click handler in a function:

functiononDoubleClick() {
    if (window.sfdcPage && window.sfdcPage.hasRun)
        sfdcPage.dblClickField(event, this);
}

Then you can just reference it from your <td> element:

<td ondblclick="onDoubleClick();"...

And anywhere else you need to invoke it from as well.

Here's a jsfiddle to demonstrate: http://jsfiddle.net/nq5aP/

Post a Comment for "Javascript Double Click Event"