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

Javascript Remoting not working, please assist



I am having an issue with a snippet of javascript on a VF page where I am hoping someone can enlighten me where the code is flawing. To give a small background, the VF page has a picklist and an input field that are read/updated by the JS. There is jquery code in the script to autcomplete the Product input text field by retrieving the list of possible matches from the controller (via remoting call). To downsize the result   I pass in the pricebook Id and the lineType from the Line Type picklist. I am trying to get the linetype to execute the code on the onchange event so to "cache" the results before the user types them in the input field. In my soe so far the line type changing event is firing the code and based on the alerts, I can see that the method in the controller is getting called and returns the list, BUT there are 2 issues on the result:


1) The .change event is not firing more than once, so the first time I cahnge the picklist value, the code fires and executes the remoting call, but any subsequent change to the picklist is not firing the code again. Why is that? shouldn't the .change always fire when changes are made to the selection of the picklist?


2) The autocomplete is not suggesting values based on the reusult from the call, meaning I don't see the pop up with the suggestions returned from the remoting call.


Below is the relevant code (VF page, js and controller method). please someone give me a hand!


 VF + js code:

var pop, prodNames, pbId, lineType, availableProds;
$j = jQuery.noConflict();
$j(function() {

    $j("select[id$='fLineType']").change(function() {
        pbId =  $j("input[id$='pbid']").val();
        lineType = $j(this).val();
        alert('Line type selected' + $j(this).val() + ' - ' + pbId );
        // call remote apex method and get chache list of Prod Names:
        SalesDocumentManager_Controller.cacheProdNames(pbId, lineType,  
           function(result, event){
                alert('Result from remote call: ' + result);
                availableProds = result;
            {escape: true}
        source: availableProds,
        minLength: 3

 controller remote method (currently returning dummy data):

//This seems to work since it returns the values created below:    
    public static String[] cacheProdNames (String pbId, String lineType) {
        system.debug('###remote action is executing');
        String[] prodNames = new List<String>();
        prodNames.add('testProd 2');
        return prodNames;