<apex:page standardController="Account">
<script type="text/javascript">
function msgBox()
{
alert("hi");
}
</script>
<apex:form id="frm">
<apex:pageBlock title="My Content" mode="edit" id="pb">
<apex:pageBlockSection title="My Content Section" columns="2" id="pbs">
<apex:inputField value="{!account.name}" id="fst"/>
<apex:inputField value="{!account.site}"/>
<apex:inputField value="{!account.type}"/>
<apex:inputField value="{!account.accountNumber}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton onclick="msgbox();" value="Save"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Add a comment
|
1 Answer
Add you script inside apex:form.. Also Javascript is case sensative so use same name in your msgBox.. Thanks to @Martin for notice..
And best practice is to add your script end of your HTML code.. So your page DOM should load faster.
<apex:page standardController="Account">
<apex:form id="frm">
<apex:pageBlock title="My Content" mode="edit" id="pb">
<apex:pageBlockSection title="My Content Section" columns="2" id="pbs">
<apex:inputField value="{!account.name}" id="fst"/>
<apex:inputField value="{!account.site}"/>
<apex:inputField value="{!account.type}"/>
<apex:inputField value="{!account.accountNumber}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton onclick="msgBox();" value="Save"/>
</apex:pageBlockButtons>
</apex:pageBlock>
<script type="text/javascript">
function msgBox()
{
alert("hi");
}
</script>
</apex:form>
</apex:page>
-
Hello ratan thanks.I just want to know what is need to write javascript inside form tag i saw code in which its wrote outside form tag and work properly.Bonny– Bonny2016-03-03 10:56:44 +00:00Commented Mar 3, 2016 at 10:56
-
@Bonny ohh my mis.. Basically issue was related to your casesensative.. And yes it will be good practice to use script inside formRatan Paul– Ratan Paul2016-03-03 11:00:40 +00:00Commented Mar 3, 2016 at 11:00