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
Shrey TyagiShrey Tyagi 

Call Javascript through <Apex:commandButton>

Hi Everyone,
      
        I have a search page that looks for opportunity records depending on the search parameters given in input texts. The search function works on OnKeyUp instance. This code given below works perfectly fine for on  ky up event . The issue is that I want to change on key up to custom button click . When I do this , the entire page seems to relaod again , including the input parametres and page gets reset completely . Can anyone please help?


Rendering parts work well when onkeyup is used . But render acts weirrd and rerenders the entire page when button is used to invoke javascript.

<apex:page controller="ProposalSearchController" sidebar="false">

  <apex:form >
  <apex:pageMessages id="errors" />

  <apex:pageBlock title="Search Proposal Records" mode="edit">

  <table width="100%" border="0">
  <tr>  
    <td width="200" valign="top">

      <apex:pageBlock title="Search Parameters" mode="edit" id="criteria">

      <script type="text/javascript">
      function doSearch() {
        searchServer(
          document.getElementById("Name").value,
          document.getElementById("OpportunityID").value,
          document.getElementById("SolicitationNo").value,

          );

      }
     
   

      </script> 

      <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors,size">
          <apex:param name="Name" value="" />
          <apex:param name="OpportunityID" value="" />
          <apex:param name="SolicitationNo" value="" />


      <table cellpadding="2" cellspacing="2">
      <tr>
        <td style="font-weight:bold;">Opportunity ID<br/>
        <input type="text" id="OpportunityID" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Solicitation #<br/>
        <input type="text" id="SolicitationNo" onkeyup="doSearch();"/>
        </td>
      </tr>



      <tr>
        <td><br/>
         <apex:commandButton value="Reset Filters" action="{!reset}"/>
           <apex:commandButton onclick="doSearch();" value="Search"/>
        </td>      
      </tr>
       
      </table>

      </apex:pageBlock>

    </td>
   
  </tr>
  </table>
  </apex:pageBlock>
  </apex:form>
      
</apex:page>