You need to sign in to do that
Don't have an account?
Ap30
Command button is not getting disabled
Hi All,
Command btton is not getting disabled. Condition is written in javascript.
============
<apex:page controller="vRegistration" id="page">
<script>
function getValidation(){
var at = document.getElementById('{!$Component.page.form.pb.pbs.amt}');
if(at.value == "")
{
document.getElementById('{!$Component.page.form.pb.pbs.email}').disabled = true;
}
else
{
return true;
}
}
</script>
<apex:form id="form">
<apex:actionFunction action="{!sendEmail}" name="sendEmail" reRender="pb" />
<apex:actionFunction action="{!generatePDF}" name="generatePdf" reRender="pb"/>
<apex:pageBlock title="Registration Form" id="pb">
<apex:pageBlockSection columns="2" id="pbs">
Company Name :<apex:inputText value="{!vcname}" id="name"/>
Amount :<apex:inputText value="{!apevent}" id="amt"/>
</apex:pageBlockSection>
<apex:outputPanel >
<apex:commandButton value="Send Email" id="email" action="{!sendEmail}" onclick="getValidation();"/>
<apex:commandButton value="Generate PDF" action="/apex/generatePDFpage" onclick="return generatePDF()" />
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Command btton is not getting disabled. Condition is written in javascript.
============
<apex:page controller="vRegistration" id="page">
<script>
function getValidation(){
var at = document.getElementById('{!$Component.page.form.pb.pbs.amt}');
if(at.value == "")
{
document.getElementById('{!$Component.page.form.pb.pbs.email}').disabled = true;
}
else
{
return true;
}
}
</script>
<apex:form id="form">
<apex:actionFunction action="{!sendEmail}" name="sendEmail" reRender="pb" />
<apex:actionFunction action="{!generatePDF}" name="generatePdf" reRender="pb"/>
<apex:pageBlock title="Registration Form" id="pb">
<apex:pageBlockSection columns="2" id="pbs">
Company Name :<apex:inputText value="{!vcname}" id="name"/>
Amount :<apex:inputText value="{!apevent}" id="amt"/>
</apex:pageBlockSection>
<apex:outputPanel >
<apex:commandButton value="Send Email" id="email" action="{!sendEmail}" onclick="getValidation();"/>
<apex:commandButton value="Generate PDF" action="/apex/generatePDFpage" onclick="return generatePDF()" />
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
>> https://webkul.com/blog/using-condition-visualforce/
The above link has an implementation that conditionally greys out the command button you can try checking this and modify it to fit your use-case.
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
Greetings!
You are not using the correct hierarchy.
Use like this. Thank you!
Regards,
Suraj Tripathi
Try the below code:
change the command busston as lie below and call the action function name from JS:
<apex:commandButton value="Send Email" id="email" onclick="getValidation();return false;"/> // this will stop the button submission.
Thanks,
Maharajan.C