You need to sign in to do that
Don't have an account?
ksmo
on the click of save button it should check condition and popup message and prevent save
I have a button update as below
<apex:commandButton id="UpdateButton" value="UPDATE" styleClass="UpdateButton" onclick="CheckAcceptOnUpdate()" action="{!doSave}"/>
on the apex class the do save does the update to the database perfectly.
But now I want that update to work only if accept checkbox is checked so I have written the onclick function
function CheckAcceptOnUpdate()
{
var accept = document.getElementById('{!$Component.formterm.terms}').checked;
if(accept==false)
{
alert("please accept terms");
}
}
The popup is working as expected and it is not preventing the update function.the action dosave is being called. If the accept checkbox is not checked, it should only show the pop up and do nothing else.
<apex:commandButton id="UpdateButton" value="UPDATE" styleClass="UpdateButton" onclick="CheckAcceptOnUpdate()" action="{!doSave}"/>
on the apex class the do save does the update to the database perfectly.
But now I want that update to work only if accept checkbox is checked so I have written the onclick function
function CheckAcceptOnUpdate()
{
var accept = document.getElementById('{!$Component.formterm.terms}').checked;
if(accept==false)
{
alert("please accept terms");
}
}
The popup is working as expected and it is not preventing the update function.the action dosave is being called. If the accept checkbox is not checked, it should only show the pop up and do nothing else.
Please use below code to prevent the calling of update function if checkbox is unchecked.
Thanks,
All Answers
Please use below code to prevent the calling of update function if checkbox is unchecked.
Thanks,