2
<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>
0

1 Answer 1

3

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>
2
  • 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. Commented 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 form Commented Mar 3, 2016 at 11:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.