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
magsy1.3942130065717605E12magsy1.3942130065717605E12 

How does onchange work with selectList

I want to download the specified file selected from the list. Always the first value in the select list is taken to download the file. I tried adding the onchange attribute but still could not get the desired output.

Page :

var newreportWin=null;
function openReportLookupPopup(name, id, popupType)
{

  console.debug('i am here...');
  if (popupType == "partner"){
    var url="/apex/PartnerLookupPopup?namefield=" + name + "&idfield=" + id;
  } else if (popupType == "customer") {
    var url="/apex/CustomerLookupPopup?namefield=" + name + "&idfield=" + id;
  }
  newreportWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
  if (window.focus)
  {
   newreportWin.focus();
  }
     return false;
}
     
function closeLookupPopup()
{
    if (null!=newreportWin)
    {
      var ReportcustomerId = document.getElementById('{!$Component.theForm.theReportPageBlock.theReportSection.theReportItem:customerReportTargetId}').value;
      var surveyName = document.getElementById('{!$Component.theForm.theReportPageBlock.theReportSection.theReportItems:Sname}').value;
      var dlLink = document.getElementById('{!$Component.theForm.downloadReportBlock.downloadReportLink}');
      if (ReportcustomerId != '') {
        dlLink.href = '/apex/SurveyExcelFile?cId=' + ReportcustomerId +'&SName='+surveyName;
        console.debug('i am here...'+surveyName);
      }
      newreportWin.close();
    }
}
</script>

  <apex:form id="theForm">
    <apex:pageMessages />
    <apex:pageBlock id="theReportPageBlock">
      <apex:pageBlockSection id="theReportSection" collapsible="false" columns="1">
        <apex:pageBlockSectionItem id="theReportItem">
          <apex:outputPanel id="thePanel">
           <apex:inputHidden value="{!ReportcustomerId}" id="customerReportTargetId" />
             <a href="#" onclick="openReportLookupPopup('{!URLENCODE($Component.customerReportTargetName)}', '{!$Component.customerReportTargetId}', 'customer');return false">Click here to search for a Customer</a>&nbsp;&nbsp;&nbsp;<apex:inputText size="80" value="{!ReportcustomerName}" id="customerReportTargetName" onFocus="this.blur()" disabled="false"/>
          </apex:outputPanel>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem id="theReportItems">
         <apex:outputPanel > Select Survey: </apex:outputPanel>
           <apex:selectList value="{!SurveyName}" size="1" id="Sname">
    <apex:selectOptions value="{!items}"/>
    <apex:actionSupport event="onchange" action="openReportLookupPopup('{!URLENCODE($Component.customerReportTargetName)}', '{!$Component.customerReportTargetId}', 'customer');return false" reRender="theForm" />
   </apex:selectList>
  </apex:pageBlockSectionItem>
      </apex:pageBlockSection>
      </apex:pageBlock>
 
  <apex:pageBlock id="downloadReportBlock">
    <apex:outputLink id="downloadReportLink">Download Report File</apex:outputLink>
  </apex:pageBlock>

</apex:form>

</apex:page>

Controller:

public class SurveyDownloadCOntroller {
  public String ReportcustomerName {get; set;}
     public Id ReportcustomerId {get; set;}

  public void reRenderDummy() {
    return; // do nothing. this is just to render the download link
  }
  String[] SurveyName = new String[]{};
public PageReference test() {
  return null;
}
public List<SelectOption> getItems() {
  List<SelectOption> options = new List<SelectOption>();
  options.add(new SelectOption('BCP Survey','BCP Survey'));
  options.add(new SelectOption('CSR Survey','CSR Survey'));
  options.add(new SelectOption('CM Survey','CM Survey'));
  return options;
}
public String[] getSurveyName() {
  return SurveyName;
}
public void setSurveyName(String[] SurveyName) {
  this.SurveyName = SurveyName;
}
}
Swati GSwati G
Hi,

ActionSupport's action is of type apexpages action. we can not use javascript function there as per documentation. instead of using actionsupport you can directly use onchange on selectList. Also, we have hardcoded the 'customer' parameter in action call.
magsy1.3942130065717605E12magsy1.3942130065717605E12
Thanks Swati. I tried doing it like the way u said but still i am not able to download the specific file according to the changed value frm the selectList