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

problem in command button
Hello Everyone,
I am facing some problem in command button. pls help me if anyone knw.
I want when i click on command button it opens the new pageblocksection with some of values. i am using javascript for the same with onclick event, it shows the pageblocksection but for some time and then refresh the page. if anyone knw pls tell me the error.
or if their any other solution for this??????
code that am using.... pls check.
<apex:page controller="TimeTable" sidebar="false"> <script> function Function() { document.getElementById('idSpan').style.display = 'block'; } </script> <apex:form > <apex:pageBlock title="Time Table"> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:pageBlockSection > <apex:inputField value="{!timetable.Date__c}"/> <apex:inputField value="{!timetable.Class__c}" /> <center><apex:commandButton value="Create Time Table" onclick="Function();"/></center> </apex:pageBlockSection> <span id="idSpan" style = "display:none"> <apex:pageBlock > <apex:pageBlockSection title="Time Table" columns="1" id="Details"> <table> <tr><th width="100">Period</th><th width="100">MON</th><th width="100">TUE</th><th width="100">WED</th><th width="100">THU</th> <th width="100">FRI</th><th width="100">SAT</th></tr> <tr><td width="100">Period-1<br/>8:00-9:00 AM</td><td width="100"><apex:inputField value="{!timetable.Teacher__c}"/></td><td width="100"><apex:inputField value="{!timetable.Teacher__c}"/></td><td width="100"><apex:inputField value="{!timetable.Teacher__c}"/></td><td width="100"><apex:inputField value="{!timetable.Teacher__c}"/></td> <td width="100"><apex:inputField value="{!timetable.Teacher__c}"/></td><td width="100"><apex:inputField value="{!timetable.Teacher__c}"/></td></tr> </table> </apex:pageBlockSection> </apex:pageBlock> </span> </apex:pageBlock> </apex:form> </apex:page>
Thanks In Advance.
Thanks Dear for reply......
Its working fine with after doing some of changes in given code...... Thanks for suggestion.....:)
All Answers
Hi Maahi,
Use the rerender attribute in the commandButton.
(For example : <apex:commandButton value="Save" onclick="javascript: xyz()" rerender="specify the id of the part you wish to display") />
This will prevent refreshing of the page.
Hope this works for you.
Thanks for reply...., i tried that also.. but not working properly...... i'll try ur example...... but if you have somthing else then pls let me knw.... or if u have code then pls post that.......
command button will refresh the page,
onclick you are just rendering some other section,
Then why you are not using simple HTML button , and call Javascript function
It will not refresh your page
Hope will help you
Thanks,
Bala
Hello Maahi;
Try adding "return false;" at the end of your buttons onclick event as below.
Hi Maahi,
I have tested the same code in my org.
Do the changes marked in red as below and this will definitely work.
Please check.
Thanks Dear for reply......
Its working fine with after doing some of changes in given code...... Thanks for suggestion.....:)