[SalesForce] how to call the javascript function through ActionFunction

In The below code the submitEmp() method not working can any one tell me how to call the javascript function through the ActionFunction

<script> 
function innerJavascript(){ 
alert('Start invoking vf action!');
submitEmp();
}
</script>

CONTROLLER

public pageReference submitEmp(){
  EMPTest__c c= new EMPTest__c();
  insert c;
  return null;
}

Best Answer

I think you're confusing some things. Actionfunctions are to expose controller (apex) methods to javascript. Actionfunctions are not to call javascript methods from apex. You may do well to read the ActionMethod documentation and examples.

Though Looking at your included code, it IS what you are looking for:

<apex:page controller="myController">
    <script> 
    myActionMethod(); //this is javascript
    </script>
    <apex:form>
            <!-- this is an apex/vf method that will be call-able from JS -->
            <apex:actionFunction name="myActionMethod" 
                                 action="{!submitEmp}" />
             <!-- the action attribute is the apex controller method you want to call -->
    </apex:form>
</apex:page>


public class myController{
    public void submitEmp(){
        EMPTest__c c= new EMPTest__c();
        insert c;
   }
}