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

Apexcommand button onclick event
Hi,
I am trying to create an "onclick" event handler for the <apex:commandbutton> tag. For some reason, it is not working properly. Here is my code:
<apex:commandbutton action="{!delete}" value="Delete" immediate="true" onclick="dislayErr()"/> function displayErr(){ if({!Account.name != 'Test User'}){ alert("You are not allowed to delete this credit card entry"); } }
Please help. Thank you.
There are many workarounds to prevent the delete action.
But as a similar solution like urs:
function displayErr(acctName)
}
if(acctName!='Test User')
{
alert(".....");
}else
{
DeleteRecord();
}
}
<apex:actionfunction name="DeleteRecord" action="{!Delete}"/>
<apex:commandButton value="Delete" onclick="DisplayErr('{!Account.Name}' "/>
Where Do you pass the Account Id through the URL in Visualforce,or apex side?
All Answers
try
Hi,
This worked partially. Apologies, I didn't explain myself very well on the first post. The edits worked, the message displayed. However, when i tried to pass a record ID through the URL, the alert did not display. How do I get the alert to display when I pass a record ID through?
In addition, how do I stop the delete function from executing if the alert displays?
Thanks for your help.
Hi Lovetolearn
You have to give Id of Test User In the Url.....
try this by designing a controller method
public class x {
public Id accId{get;set;}
public Account account{get;set;}
x() {
accId = ApexPages.currentPage().getParameters.get('Id')
account = [select Id,Name from Account where Id=:accId];
}
public Account getAccount() {
return account;
}
}
There are many workarounds to prevent the delete action.
But as a similar solution like urs:
function displayErr(acctName)
}
if(acctName!='Test User')
{
alert(".....");
}else
{
DeleteRecord();
}
}
<apex:actionfunction name="DeleteRecord" action="{!Delete}"/>
<apex:commandButton value="Delete" onclick="DisplayErr('{!Account.Name}' "/>
Where Do you pass the Account Id through the URL in Visualforce,or apex side?
Thanks everyone for all the help. I appreciate it.