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

Help with setting a SelectList value in PageBlockTable using javascript

I have a Pageblocktable of myWrapper objects and two of it's columns are SelectList and Checkbox. Both of these columns correspond to peroperties of myWrapper object. When the VF page renders the selctlist default value is blank and only when the checkbox next to it (in the same row) is checked the Select List value needs to be defaulted to the first value in select list(which comes from the controller).
I am using javascript funaction and have all vales available in selectlist. I am not able to figure how to set value in the select list of the row on which checkbox was checked. I am trying javascript jquery. I am passing in the object Id of the object in that row to javascript. 
        function selectDefaultCategory (objectId) {
            var categories = new Array();
            var json = '{! tripCategories }';
            <apex:repeat var="category" value="{!tripCategories}">
<apex:pageBlockTable id="myTable" value="{! myWrapperList }" var="each">     
<apex:column headerclass="alignCenter" styleClass="alignCenter"  id="requiredColumn" headerValue="Required"  >
    <apex:inputCheckbox value="{!each.Required__c}" id="required" onclick="selectTripCategory(! each.Id)" />

<apex:column headerValue="tripCategory" >
    <apex:selectList value="{! each.category}" size="1">
        <apex:selectOptions value="{! tripCategories}" id="tripCategory" />

Damon ShawDamon Shaw
Hi MK7,

There are likely better answers out there but this is what I have done in the past for similar issues

add a rowClasses="tableRow" to your apex:pageBlockTable, then add style classes to both your checkbox and selectlist
<apex:pageBlockTable id="myTable" value="{! myWrapperList }" var="each" rowClasses="tableRow">     
    <apex:column headerclass="alignCenter" styleClass="alignCenter"  id="requiredColumn" headerValue="Required"  >
        <apex:inputCheckbox value="{!each.Required__c}" id="required" onclick="selectTripCategory(! each.Id)" styleClass="checkbox"/>
    <apex:column headerValue="tripCategory" >
        <apex:selectList value="{! each.category}" size="1" styleClass="selectList">
            <apex:selectOptions value="{! tripCategories}" id="tripCategory" />

then using jquery you can watch for a change to your checkbox, find it's parent row, then the row's child selectlist.

I've not tested this but it should get you close
$(".checkbox").change(function() {
    if(this.checked) {
        var row = $(this).closest('.tableRow');
        var select = row.find('.selectList');

jayaram reddyjayaram reddy

<apex:pageBlockSectionItem >
        <apex:selectList value="{!PicklistValues[0]}" multiselect="false" size="1" style="width: 1000px">
            <apex:selectOption itemLabel="None" itemvalue="None" ></apex:selectOption>
          <apex:selectOption itemLabel="Yes"  itemvalue="Yes"></apex:selectOption>
          <apex:selectOption itemLabel="No" itemvalue="No"></apex:selectOption>

for(integer i=0;i<1;i++){
                OBJECT  response= new OBJECT();
            response.Free_Text__c = PicklistValues[0];