You need to sign in to do that
Don't have an account?
Passing value from javascript to controller's wrapper class property in vf page
I have a page and i am displaying a list of items from a wrapper class in the page.
As a requirement i have an input text box and inputcheckbox for all the records displayed on the list.
I need to populate a field in the list of recods from the input text box data based on the input check box.
I can do it through <apex:ActionSupport> but my client need it to be done with javascript so that whatever i am typing will get instantly populated in all the textbox for all the selected list of records.
The issue i am facing is after populating all the selected records with data from text box i am not getting that data in the wrapper class list in the controller. Is that's not possible in sales force??
Below is my code for VF page and Controller.
<apex:page sidebar="false" controller="AccountList"> <script> function method1(data1) { var d1=document.getElementById(data1).value; el = document.getElementsByTagName("input"); var j=0; var k=0; var checkboxes= new Array(); var textbox= new Array(); var textboxes= new Array(); var checkdindex = new Array(); var updateElmnts = new Array(); for( var i=0;i<el.length;i++) { if(el[i].id.indexOf("txtid")!=-1) { textboxes[j] = el[i]; textbox[i] =el[i]; } if(el[i].id.indexOf("chkboxcustom2")!=-1) { if(el[i].checked) { checkboxes[k] = el[i]; checkdindex[k] = i; updateElmnts[k] = parseInt(i)+1; k++; } } j++; } for(var a=0;a<k;a++) { textbox[updateElmnts[a]].value = d1; } } </script> <apex:pageBlock id="pgblock1" > <apex:form id="form1"> <apex:commandbutton value="Save" style="align:center" action="{!saveAll}" /> <br/> <apex:outputText >Name</apex:outputText><br/> <apex:inputText onchange="method1('{!$Component.pgblock1.form1.fname}');" id="fname" /> <br/><hr/> </apex:form> </apex:pageBlock> <apex:pageBlock id="pgblock3" > <apex:form id="form3"> <apex:pageblockTable value="{!Accounts}" var="acc" id="pgbltab"> <apex:column > <input type="Checkbox" id="chkboxcustom2"/> </apex:column> <apex:column value="{!acc.name}" id="name"/> <apex:column value="{!acc.type}"/> <apex:column > <input type="text" id="txtid" disabled="disabled" value="{!acc.test}"/> </apex:column> </apex:pageblockTable> </apex:form> </apex:pageBlock> </apex:page> ----------------------------------------- Controller ******************** public with sharing class AccountList { public class accounts { public String name{get;set;} public String type{get;set;} public String test{get;set;} } public List<accounts> accList = new List<accounts>(); public string text{get;set;} public AccountList() { } public String test{get;set;} public AccountList(ApexPages.StandardController controller) { } public List<accounts> getAccounts(){ accList.clear(); for(Account a: [select name,type, test__c from account limit 5]) { Accounts acc = new Accounts(); acc.name = a.name; acc.type = a.type; accList.add(acc); } return accList; } public void saveAll() { System.debug('---------'+accList); } }
Please help me, i am able to populate the selected records with data from the input text box.
I can't use action support since my client needs the data to be populated instanatly through java script . I am finding the way we can pass it from the java script to controler's wrapper list.
The action support i am done but my client suggested to check with JavsScript as well.
I suggest you to use Actionfunction not Action Support.