+ Start a Discussion
SoozeeSoozee 

setting value of drop down

Hi - I have a drop down on a VF page that displays the number of pages of records.

I want to be able to programmatically set the drop down value to '1' when the user sorts by any column header.

I know this should be pretty simple, but I've been searching for an answer and cannot find anything.....

Here's the VF code for populating the drop down with data from the controller

 

<apex:selectList id="pgnm" size="1" value="{!pagenum}" onChange="changePage(this.options[this.selectedIndex].text);">
             	<apex:selectOptions value="{!pageNumbers}"/>
                </apex:selectList>
                <br/>
                <apex:actionFunction name="changePage" action="{!goToPage}" rerender="out" status="loading">
     				<apex:param assignTo="{!pagenum}" value="" name="pagenum"/>
   				</apex:actionFunction>

 

Here's the code that I want to cause the reset of the drop down to '1':

<apex:facet name="header" >
                    <apex:outputLink onclick="SortByStuLastName();return false;">Student Name</apex:outputLink>
                </apex:facet>

 I've tried adding a javascript function after the return false;  and calling it like this:setPageNum(' {!$Component.ltrowner}') but this did not work...

function setPageNum(val){
		document.getElementById(val).value = '1';
  }

 Your help is greatly appreciated!

mast0rmast0r

I would try it with jQuery. It triggers on the outputLink click and sets the selected option value to 1:

 

<apex:selectList id="pgnm" size="1" value="{!pagenum}" onChange="changePage(this.options[this.selectedIndex].text);">
 ...
</apex:selectList>

<apex:outputLink onclick="SortByStuLastName();return false;" styleClass="linkDummyClass">
    Student Name
</apex:outputLink>


<script>
jQuery('.linkDummyClass').click(function(){
    jQuery('[id$=pgnm] option:selected').val('1');
});
</script>
reddygari403reddygari403

<apex:page sidebar="false" controller="DependentClassabcd">
<apex:form id="f1">
Departments: <apex:selectList value="{!selDept}" multiselect="false" size="1">
<apex:actionSupport event="onchange" reRender="out"/>
<apex:selectOptions value="{!deptnames}">
</apex:selectOptions>
</apex:selectList> <br/>

Employees: <apex:selectList multiselect="false" id="out" size="1" value="{!emp_name}" onchange="employee()">
<apex:selectOptions value="{!empnames}" >

</apex:selectOptions>
</apex:selectList>
<apex:actionFunction action="{!emp_details}" name="employee" reRender="f1"/>
<apex:detail subject="{!emp_id}"/>
</apex:form>
</apex:page>

 

 

class:

================

public with sharing class DependentClassabcd {

public String emp_id { get; set; }

public PageReference emp_details()
{
employee__c e=[select id,name from employee__c where name=:emp_name];
emp_id =e.id;
return null;
}


public String emp_name { get; set; }

public String selDept { get; set; }
List<selectOption> empOptions = new List<selectOption>();
public List<selectOption> getEmpnames() {
empOptions.clear();
empOptions.add(new selectOption('--None--','--None--'));
for(employee__c objEmp : [select name from employee__c where dept__r.name=:selDept])
{

empOptions.add(new selectOption(objEmp.name,objEmp.name));
}
return empOptions;
}

List<selectOption> deptOptions ;
public List<selectOption> getDeptnames()
{
deptOptions = new List<selectOption>();
deptOptions.add(new selectOption('--None--','--None--'));
for(Department__c objDept : [select name from Department__c])
{
deptOptions.add(new selectOption(objDept.name,objDept.name));
}
return deptOptions;
}
}