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

command button with javascript issue
<apex:page sidebar="false" showheader="true"> <script type="text/javascript"> function link() { window.location= 'https://c.ap1.visual.force.com/apex/helloworld'; } </script> <apex:form id="new"> <apex:commandButton styleClass="groovybutton" onclick="link();" id="button1" value="commond button"/> <input type="button" name="groovybtn1" onclick="link()" class="groovybutton" value="HTML button"/> </apex:form> </apex:page>
In the above code snippet
when i click the command button , page redirect is not happening. However, i click HTML button page redirect is happening.
please help me to fix it
Hi,
<apex:commandButton> is a action component and expect to execute controller method in response to click event, if you dont give action attribute then it will simply refersh the page. To prevent this behaviour just return false from onclick event like -
<apex:commandButton styleClass="groovybutton" onclick="link();return false;" id="button1" value="commond button"/>
Hope it would work.
All Answers
Hi,
<apex:commandButton> is a action component and expect to execute controller method in response to click event, if you dont give action attribute then it will simply refersh the page. To prevent this behaviour just return false from onclick event like -
<apex:commandButton styleClass="groovybutton" onclick="link();return false;" id="button1" value="commond button"/>
Hope it would work.
Works.Thanks for quick response Alok