You need to sign in to do that
Don't have an account?
Nuevo9763
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.
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}"> categories.push('{!category.value}'); </apex:repeat> //j$('[id$=tripCategory]').val(categories[1]); } <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> <apex:column headerValue="tripCategory" > <apex:selectList value="{! each.category}" size="1"> <apex:selectOptions value="{! tripCategories}" id="tripCategory" /> </apex:selectList> </apex:column> </apex:pageBlockTable>
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
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
<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>
</apex:selectList>
</apex:pageBlockSectionItem>
APEX CLASS:
for(integer i=0;i<1;i++){
OBJECT response= new OBJECT();
response.Free_Text__c = PicklistValues[0];
ListResponse.add(response);
}