In my JSF page, within <script> tags I have following content.
<script>
function func() {
alert("Button clicked");
}
window.onload = function() {
#{rich:element("btn")}.onclick = func;
}
</script>
And I have an a4j button in page body.
<a4j:commandButton id="btn" value="save" />
After the page is loaded I click the button and it successfully displays the alert.
But what I want now is to set the function func for the oncomplete event of the button. I tried in following way but didn’t work. Please help.
window.onload = function() {
#{rich:element("btn")}.oncomplete = func;
}
I prefer the answer without jQuery.
I finally found a workaround.
I added the function to the
oncompleteevent initially, and change the body of the function at runtime.Then within my
<script></script>I added the following code.