You need to sign in to do that
Don't have an account?
Shiv Shankar
what is the use of return statement on onlclick event
Hi Friends,
What is the use of return statement here
<apex:commandButton action="controllerMethod()" onclick="return javaScriptMethod()" rerender="abc" />
Since it is urgent.
I would suggest a workaround.
Did you ever try this workaround ?
http://boards.developerforce.com/t5/Visualforce-Development/what-is-the-use-of-return-statement-on-onlclick-event/m-p/636117/highlight/false#M65576
Hi
I am not sure about your business requirement.
But return statement javascript onclick is validate the form action of visualforce. If onclick return true javascript will submit the form and allow to call the action method from controller and if javascript return false it will not call the action method from controller.
It wll also check the button type from submit to normal button.
In your case you are using "reRender" which automatic add AJAX method in form and add default return false.
Check code
VF
<apex:page >
<apex:form >
<apex:inputText id="testid"/>
<apex:commandButton action="controllerMethod()" onclick="return validateItemNo()" value="Click" reRender="testid"/>
</apex:form>
Client code generate by SFDC
<input name="j_id0:j_id1" value="j_id0:j_id1" type="hidden">
<input id="j_id0:j_id1:testid" name="j_id0:j_id1:testid" type="text">
<input class="btn" id="j_id0:j_id1:j_id2" name="j_id0:j_id1:j_id2"
onclick="return validateItemNo();A4J.AJAX.Submit('j_id0:j_id1',event,{'similarityGroupingId':'j_id0:j_id1:j_id2','parameters':{'j_id0:j_id1:j_id2':'j_id0:j_id1:j_id2'} } );return false;" value="Click" type="button">
<div id="j_id0:j_id1:j_id4"></div>
Now code without RenderAs
<apex:page >
<apex:form >
<apex:inputText id="testid"/>
<apex:commandButton action="controllerMethod()" onclick="return validateItemNo()" value="Click"/>
</apex:form>
Code generate by SFDC
<input name="j_id0:j_id1" value="j_id0:j_id1" type="hidden">
<input id="j_id0:j_id1:testid" name="j_id0:j_id1:testid" type="text">
<input name="j_id0:j_id1:j_id2" value="Click" onclick="return validateItemNo()" class="btn" type="submit">
<div id="j_id0:j_id1:j_id4"></div>
You can check its will work according to your way. But when you add "renderAs" Salesforce default will add false return and form will not submitted to controller.
~Thanks,
Onkar Kumar
Hi Onkar,
thanku very much to make my fundamental lilltle more clear by your valubel reply.
Onkar but in my requirement i need to rerender the other bolcks, is there any alternative for that, so i can call the apex method also and can display error through java script and reRender also...
Thanks,