function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AndraskoAndrasko 

commandbutton don't work after i use javascript

Hy everyone,

 

I have a vf page with a form. The form consists of input fields and two select. I use javascript to change the two select itmes. After I insert the javascript code to my page, the command button go wrong. If I clicks on the button the page reloaded.

 

Here is my simplified page:

 

<apex:page ..." >
  
  <script type="text/javascript">  
    function moveOptions(sourceID, destID) {
            ...
  </script>
   
    <apex:form id="id_01" >
      <table class="dfTable">
        <tr class="odd">
          <td class="column1">Name*:</td>
          <td>
            <apex:inputText value="{!name}"/>
          </td>
        </tr>
        <tr class="odd">
          <td class="column1">
            <apex:selectList id="actUser" ... >
              ...
            </apex:selectList>
          </td>
          <td>
            <a href="#" id="add" onClick="moveOptions(...)')" >&gt;&gt;</a>
          </td>
          <td>
            <apex:selectList id="availableUser" ... >
              ...
            </apex:selectList>  
          </td>
        </tr>
      </table>
      <apex:commandButton action="{!cancel}" title="Cancel" value="Cancel"  />
      <apex:commandButton action="{!save}" title="Save"  value="Save" />
    </apex:form>

 

Is anyone know why happening this? I spent a lot of time to solve it, but I haven't got any answer or solution.

 

vhanson222vhanson222

If you don't want your VF page to refresh when you click a button, try adding this to your buttons:   onComplete="return false;"

 

That *should* stop your page from refreshing.

 

i.e.

 

      <apex:commandButton action="{!cancel}" title="Cancel" value="Cancel" onComplete="return false;" />
<apex:commandButton action="{!save}" title="Save" value="Save" onComplete="return false;" />
AndraskoAndrasko

My problem is not the relodaing.

If I clicks on the command button, nothing happen.

Before I inserted the javascript code, the button call the controller save or cancel method.

bmabma

Do you have any error in your javascript?

 

Sometime, JS error would malfunction a page.

AndraskoAndrasko

If I don't call the javascript, everything is ok. ---> the button works well.

If I call the javascript the button go wrong.

 

Maybe something happens in the controller.