You need to sign in to do that
Don't have an account?
arabisays
JavaScript in Visualforce Page
Hi. I am new to sales force. I have to perform a simple task.
When clicking an apex command button , it should alert a message through JavaScript.
Please see my code.
<apex:page standardController="Book__c">
<script>
alertSample(){
alert("Hello");
}
</script>
<apex:form >
<apex:commandButton oclick="alertSample()" value="Hello"/>
<apex:PageBlock title="Book View">
<apex:outputField value="{! Book__c.Name}"/>
<apex:detail />
</apex:PageBlock>
</apex:form>
</apex:page>
But I am not getting expected response. Please help.
When clicking an apex command button , it should alert a message through JavaScript.
Please see my code.
<apex:page standardController="Book__c">
<script>
alertSample(){
alert("Hello");
}
</script>
<apex:form >
<apex:commandButton oclick="alertSample()" value="Hello"/>
<apex:PageBlock title="Book View">
<apex:outputField value="{! Book__c.Name}"/>
<apex:detail />
</apex:PageBlock>
</apex:form>
</apex:page>
But I am not getting expected response. Please help.
use this code you wlll get the alert as you like.
<apex:page standardController="Book__c">
<script>
function alertSample()
{
alert("Hello");
}
</script>
<apex:form >
<apex:commandButton onclick="alertSample();" value="Hello"/>
<apex:PageBlock title="Book View">
<apex:outputField value="{!Book__c.Name}"/>
<apex:detail />
</apex:PageBlock>
</apex:form>
</apex:page>
if you dont get requirment reply me so that i will ahelp you
or else if you reach ur solution.
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Srinivas
SFDC Certified Developer
All Answers
You have missed out to call as 'function' before giving function name.
<script>
function alertSample() {
alert("Hello");
}
</script>
use this code you wlll get the alert as you like.
<apex:page standardController="Book__c">
<script>
function alertSample()
{
alert("Hello");
}
</script>
<apex:form >
<apex:commandButton onclick="alertSample();" value="Hello"/>
<apex:PageBlock title="Book View">
<apex:outputField value="{!Book__c.Name}"/>
<apex:detail />
</apex:PageBlock>
</apex:form>
</apex:page>
if you dont get requirment reply me so that i will ahelp you
or else if you reach ur solution.
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Srinivas
SFDC Certified Developer