I want to call a Javascript
function as well as issue a backend call at the moment a button is clicked.
This is my code right now :
<apex:commandButton value="Search" action="{!objectCollection}" style="margin-left:10px" reRender="source_search">
<apex:param name="source" value="true"/>
<apex:param name="target" value="false"/>
</apex:commandButton>
Is this possible?
Best Answer
Yes, you can.
You can use the
onclick
attribute like below.UPDATE
Based on your comments below, you want to call both JavaScript and Controller's function only if the input is valid. You can achieve this with following code:
The idea is that the
isInputValid()
is also a JS function that will validate the input and returntrue
if everything is valid, andfalse
if the input is invalid. If theisInputValid()
returnsfalse
, neither the controller's function, nor your JavaScript function in theelse
statement will get called.