You need to sign in to do that
Don't have an account?

Triggering Javscript Events -- click();
I know that we can call the click() event of a button from Javascript like below ...but I can't access the click event of an inputText element.
Thanks for the help!!!!
var btnCopy = document.getElementById("{!$Component.btnCopy}");
btnCopy.click(
<apex:inputText onClick="a();" /> <apex:inputText id="zz" onClick="alert('hi');"/> <script> function a() { document.getElementById("{!$Component.zz}").click(); } </script>
Just tried it. Turns out the DOM element name is "onclick" (all lowercase) not "onClick". It works if you change to
<apex:inputText value="{!Params.ContractName}" onclick="document.getElementById('{!$Component.zz}').onclick();" />
<apex:inputText value="{!contractName}" id="zz" onclick="alert('hi');" />
All Answers
When you want to do something like that, you must use <apex:actionsupport>... example below:
<!-- Page: -->
<apex:page controller="exampleCon">
<apex:form>
<apex:outputpanel id="counter">
<apex:outputText value="Click Me!: {!count}"/>
<apex:actionSupport event="onclick"
action="{!incrementCounter}"
rerender="counter" status="counterStatus"/>
</apex:outputpanel>
<apex:actionStatus id="counterStatus"
startText=" (incrementing...)"
stopText=" (done)"/>
</apex:form>
</apex:page>
/*** Controller: ***/
public class exampleCon {
Integer count = 0;
public PageReference incrementCounter() {
count++;
return null;
}
public Integer getCount() {
return count;
}
}
hope that helps.
Thanks for the post vRay, but I don't think this solves my problem.
actionSupport is to hook into an elements event handling, I want to trigger the event of an element from Javascript, like btnCopy.click();
Thanks again !
Your code looks ok to me for invoking the input element's "click()" method. But according to my Javascript reference, calling the click method simulates a mouse click event but DOES NOT invoke any onclick handler associated with the input element.
Thanks ! So how would I go about invoking an event handler for an element.
if you just want to call the event handler, you can use obect.onclick() to call whatever function is assigned to the onclick property. (You may need to test it is non-null first).
Just tried it, no luck!
<apex:inputText value="{!Params.ContractName}" onclick="document.getElementById('{!$Component.zz}').onClick();" />
<apex:inputText value="{!contractName}" id="zz" onclick="alert('hi');" />
Thanks!
Just tried it. Turns out the DOM element name is "onclick" (all lowercase) not "onClick". It works if you change to
<apex:inputText value="{!Params.ContractName}" onclick="document.getElementById('{!$Component.zz}').onclick();" />
<apex:inputText value="{!contractName}" id="zz" onclick="alert('hi');" />
Thanks a bunch, worked like a charm!