function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nasknask 

usage of Doctype="html-5.0" stops ActionFunctoin execution

Hello Everyone,

 

I have a VF page where i use a Java script to invoke a apex:actionfunction which works perfectly fine wher we dont declare doctype on the page. But the same Javascript doesnt invoke the actionfunction when the page has doctype declared? Can any one help.

 

I am using HTML-5.0 in order to use the new apex:input & type attribute on vf page. which i have not shown in the page to keep it simple.

 

Thanks

 

Ashok

 

This code works:

 

<apex:page controller="cocController"  id="page" >
<apex:form >

 

<script type="text/javascript">

    function exportImage(){
                    saveFormUnique();
        }
   

</script>

<apex:actionfunction name="saveFormUnique" action="{!saverecord}">

<apex:pageBlock id="blk1">
 
    <apex:pageblockButtons location="bottom">
       <apex:commandButton onclick="exportImage();" value="Save  Generate PDF"  oncomplete="alert('ok');" />
    </apex:pageblockButtons>

</apex:pageBlock>

</apex:form>

</apex:page>

 

This code doesnt work:

 

 

<apex:page controller="cocController"  id="page" >
<apex:form >

 

<script type="text/javascript">

    function exportImage(){
                    saveFormUnique();
        }
   

</script>

<apex:actionfunction name="saveFormUnique" action="{!saverecord}" doctype="html-5.0">

<apex:pageBlock id="blk1">
 
    <apex:pageblockButtons location="bottom">
       <apex:commandButton onclick="exportImage();" value="Save  Generate PDF"  oncomplete="alert('ok');" />
   
    </apex:pageblockButtons>

</apex:pageBlock>

</apex:form>

</apex:page>

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Vinita_SFDCVinita_SFDC

Hi,

 

Wondering why it is not working, i just tried out this example and it is working for me:

 

VF page:

 

<apex:page docType="html-5.0" controller="exampleCon">
<apex:form >
<!-- Define the JavaScript function sayHello-->
<apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out"
status="myStatus"/>
</apex:form>
<apex:outputPanel id="out">
<apex:outputText value="Hello "/>
<apex:actionStatus startText="requesting..." id="myStatus">
<apex:facet name="stop">{!username}</apex:facet>
</apex:actionStatus>
</apex:outputPanel>
<!-- Call the sayHello JavaScript function using a script element-->
<script>window.setTimeout(sayHello,2000)</script>
<p><apex:outputText value="Clicked? {!state}" id="showstate" /></p>
<!-- Add the onclick event listener to a panel. When clicked, the panel triggers
the methodOneInJavascript actionFunction with a param -->
<apex:outputPanel onclick="methodOneInJavascript('Yes!')" styleClass="btn">
Click Me
</apex:outputPanel>
<apex:form >
<apex:actionFunction action="{!methodOne}" name="methodOneInJavascript"
rerender="showstate">
<apex:param name="firstParam" assignTo="{!state}" value="" />
</apex:actionFunction>
</apex:form>
</apex:page>


===============================================

 

Controller:

public class exampleCon {
String uname;
public String getUsername() {
return uname;
}
public PageReference sayHello() {
uname = UserInfo.getName();
return null;
}
public void setState(String n) {
state = n;
}
public String getState() {
return state;
}
public PageReference methodOne() {
return null;
}
private String state = 'no';
}

 

All Answers

Vinita_SFDCVinita_SFDC

Hello Nask,

 

Try this:

 

<apex:page docType="html-5.0" controller="cocController"  id="page" >
<apex:form >

 

<script type="text/javascript">

    function exportImage(){
                    saveFormUnique();
        }
   

</script>

<apex:actionfunction name="saveFormUnique" action="{!saverecord}" >

<apex:pageBlock id="blk1">
 
    <apex:pageblockButtons location="bottom">
       <apex:commandButton onclick="exportImage();" value="Save  Generate PDF"  oncomplete="alert('ok');" />
   
    </apex:pageblockButtons>

</apex:pageBlock>

</apex:form>

</apex:page>

nasknask

Sorry vinita,

 

I got the wrong code pasted in my question. i have tried exaclty like you. Its not working.

Vinita_SFDCVinita_SFDC

Hi,

 

Wondering why it is not working, i just tried out this example and it is working for me:

 

VF page:

 

<apex:page docType="html-5.0" controller="exampleCon">
<apex:form >
<!-- Define the JavaScript function sayHello-->
<apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out"
status="myStatus"/>
</apex:form>
<apex:outputPanel id="out">
<apex:outputText value="Hello "/>
<apex:actionStatus startText="requesting..." id="myStatus">
<apex:facet name="stop">{!username}</apex:facet>
</apex:actionStatus>
</apex:outputPanel>
<!-- Call the sayHello JavaScript function using a script element-->
<script>window.setTimeout(sayHello,2000)</script>
<p><apex:outputText value="Clicked? {!state}" id="showstate" /></p>
<!-- Add the onclick event listener to a panel. When clicked, the panel triggers
the methodOneInJavascript actionFunction with a param -->
<apex:outputPanel onclick="methodOneInJavascript('Yes!')" styleClass="btn">
Click Me
</apex:outputPanel>
<apex:form >
<apex:actionFunction action="{!methodOne}" name="methodOneInJavascript"
rerender="showstate">
<apex:param name="firstParam" assignTo="{!state}" value="" />
</apex:actionFunction>
</apex:form>
</apex:page>


===============================================

 

Controller:

public class exampleCon {
String uname;
public String getUsername() {
return uname;
}
public PageReference sayHello() {
uname = UserInfo.getName();
return null;
}
public void setState(String n) {
state = n;
}
public String getState() {
return state;
}
public PageReference methodOne() {
return null;
}
private String state = 'no';
}

 

This was selected as the best answer