How to call Javascript from Command button in Visuaforce page?

How to call Javascript from Command button in Visuaforce page?

Sample Visualforce page:

<apex:page >
<script>
    function show(){
        alert(‘Test’);
    }
</script>
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockButtons >            
            <apex:commandButton value=”Store” onclick=”show();”/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>
</apex:page>


Output

Cheers!!!

Leave a Reply