9
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

1 Answer 1

8

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
    Commented Apr 14, 2016 at 10:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .