7
function check(){
   var user = document.getElementById('pg:frm:nPB:ip').value;
   if(user == ''){
       alert('Please Enter noise Name before Proceeding.');
       return true;
   }
   else{
     noiseSearch();
     return true;
    }
 </script>
 <apex:commandButton value="Search" onclick="check();" 
                        action="{!noiseSearch}"  reRender="nPbt" />

controller

public class controller{
    public pageReference noiseSearch(){
         //logic
         return null;
    }
}

,i tired with about code,but my noisesearch() not called,i want to know why it is not called

6

Use actionfuntion here

apex:actionFunction

A component that provides support for invoking controller action methods directly from JavaScript code using an AJAX request. An component must be a child of an component.

So your button will be

<apex:commandButton value="Search" onclick="check();" reRender="nPbt" />

And your script function

  function check(){
    var user = document.getElementById('pg:frm:nPB:ip').value;
    if(user == ''){
        alert('Please Enter noise Name before Proceeding.');
        return true;
    }
    else
        noiseSearchAF();
        return true;
   }

And your action function will be

<apex:actionFunction action="{!noiseSearch}" name="noiseSearchAF" rerender="nPbt">

Another way use Javascript remoting

Check JavaScript Remoting Example

1
  • 1
    thanq,solved my problem
    – Satya
    Apr 14 '16 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.