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

onclick function not working for commandlink
Hi All,
Below is my code:
VF Page:
<apex:page controller="SummaryPdfDispController" standardStylesheets="false" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock Id="status1">
<apex:commandLink action="{!SendEmail}" value="Email Dossier" reRender="status1" styleClass="element" onclick="this.value = 'Sending...'"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Note:
1. If I omit the onclick functionality then action- SendEmail is called.
2. I could not use commandbutton as per project purpose.
3. I have used javascript on onclick functionality, but it did not work.
Below is my code:
VF Page:
<apex:page controller="SummaryPdfDispController" standardStylesheets="false" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock Id="status1">
<apex:commandLink action="{!SendEmail}" value="Email Dossier" reRender="status1" styleClass="element" onclick="this.value = 'Sending...'"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Note:
1. If I omit the onclick functionality then action- SendEmail is called.
2. I could not use commandbutton as per project purpose.
3. I have used javascript on onclick functionality, but it did not work.
<apex:commandbutton id = "s1" value="Submit" onclick="performValidation()"/>
<apex:actionFunction name="afterValidation" action="{!callAction" rerender="ids of the components you want to refresh" />
Now in javascript function,
function performValidation()
{
//after your stuff
//invoke the actionFunction
afterValidation();
}
http://salesforce.stackexchange.com/questions/24250/get-commandlink-value-using-js
https://developer.salesforce.com/forums?id=906F000000098yTIAQ
Please let us know if this will help u
You can try below dummy code.
It uses onclick on commandlink, which calls a javascript function and which calls a backend function using actionFunction.
Regards
Mohit Bansal
In case, you face any issue, drop me message on forum or Skype me @mohit_bansal17, if you need any help.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
<apex:page controller="SummaryPdfDispController" standardStylesheets="false" showHeader="false" sidebar="false" >
<script>
function send()
{
alert('Hi');
this.value='Sending... ';
alert('Yes');
send1();
}
</script>
<apex:form Id="status">
<apex:actionFunction action="{!SendEmail}" name="send1" reRender="status1"/>
<apex:pageBlock Id="status1">
<apex:commandLink value="Email Dossier" styleClass="element" onclick="send()"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Note: I could not use the actionstatus function, as it is showing Sending... progress outside the button, but not inside it.
You Can use loading image in this case. You can add actionstatus in action function to show loading image.
http://amitsalesforce.blogspot.in/2015/02/progress-barloading-image-on_11.html
Thanks@Amit- The functionality as per your code is working. But, I wanted to show Sending... in the button for progress, not outside it. Please reply for the same. Please check my code just above (2nd one). If we keep alert on "this.value", it shows undefined. I wanted to change "Email Dossier" to "Sending..." when we click the button.
Note: I wanted to show button as a link & I could not use commandbutton.
You can use apex:commandLink and set styleClass = "btn", using this it will represent link as button.
Secondly for displaying dynamic text on button click,kindly refer below code:
Regards
Mohit Bansal
In case, you face any issue, drop me message on forum or Skype me @mohit_bansal17, if you need any help.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help.
You can use apex:commandLink and set styleClass = "btn", using this it will represent link as button.
Secondly for displaying dynamic text on button click,kindly refer below code:
Regards
Mohit Bansal
In case, you face any issue, drop me message on forum or Skype me @mohit_bansal17, if you need any help.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help.
Kindly share, my solution, helped you to resolve your issue or you still need any assistance.
Regards
Mohit Bansal
Please look at the below code:
VF Page:
<apex:page controller="SummaryPdfDispController" standardStylesheets="false" showHeader="false" sidebar="false" >
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />
<script>
function send() { $("#j_id0\\:status\\:status1\\:email_1").html("Sending..."); }
</script>
<apex:form Id="status">
<apex:actionFunction action="{!SendEmail}" name="send1" reRender="status1"/>
<apex:pageBlock Id="status1">
<apex:commandLink action="{!SendEmail}" value="Email Dossier" onclick="send()" id="email_1" reRender="status1" />
</apex:pageBlock>
</apex:form>
</apex:page>
Note:
1. Function send() is tedious one. We have to go to console & paste the id as shown above. You could also use this example as the solution to show the progress.
2. We have to use jquery. The function is $(selector).html (to point out the inner html of the commandlink function).