You need to sign in to do that
Don't have an account?

help with passing the variable from java script function to apex class
My Visual force page:
My Apex Class:
<apex:page standardcontroller="Program_Member_MVN__c" extensions="ProgramMemberCaseAttachment" showHeader="false" > <head> <apex:includescript value="//code.jquery.com/jquery-1.11.1.min.js" / > <apex:includescript value="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" /> <apex:stylesheet value="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css" /> <script> j$ = jQuery.noConflict(); j$(document).ready( function () { var contactTable = j$('[id$="accounttable"]').DataTable({ }); }); function Callmefunc(id) { alert(''+id); var type = document.getElementById(id).value; alert(type); check(type); //return true; } </script> </head> <apex:form > <body> <table id="accounttable" class="display" > <thead> <tr> <th>Edit</th> <th>ID</th> <th>Name</th> <th>Type</th> <th>Attachment Name</th> <th>Description</th> </tr> </thead> <tbody> <apex:actionFunction name="check" action="{!processSelected1}"> <apex:param name="Mahavir" value=""/> </apex:actionFunction> <!--<apex:inputHidden value="{!AttType}" id="myHiddenField"/>--> <apex:repeat value="{!PMresults}" var="N"> <tr> <!--<td><apex:commandLink value="Edit" action="{!URLFOR($Action.Attachment_Type__c.Edit, N.Id ,[saveURL='/'+N.Id,retURL='/'+N.Id,saveandnewURL='/'+N.Id])}" target="_blank" styleClass="btn" style="text-decoration:none;padding:1px;"/> --> <td><apex:commandLink value="Save" action="{!processSelected}"> <apex:param name="{!N.Program_Memeber_Id__c}" value="{!N.Program_Memeber_Id__c}" assignTo="{!Attid}"/> <!--<apex:param name="{!N.Type__c}" value="{!N.Type__c}" assignTo="{!AttType}"/> --> </apex:commandLink> </td> <td><apex:outputField value="{!N.Program_Memeber_Id__c}" /></td> <td><apex:outputLink value="/{!N.Id}" target="_blank">{!N.Name}</apex:outputLink></td> <td><apex:inputField value="{!N.Type__c}" id="Check" onchange="Callmefunc('{!$Component.check}');"> <apex:param name="Check" value="{!N.Program_Memeber_Id__c}" assignTo="{!Attid}"/> </apex:inputField> </td> <!--<td><apex:outputtext value="{!Attid}"/></td>--> <td><apex:outputField value="{!N.Attachement_Name__c}"/></td> <td><apex:outputField value="{!N.Attachment_Description__c}"/></td> <!--<td>{!N.At.LastModifiedDate}</td>--> <!--<td> <apex:outputField value="{!N.At.Description}"/></td>--> </tr> </apex:repeat> </tbody> </table> </body> </apex:form> </apex:page>I am trying to update type field when save button is pressed.I am storing the input field value in the variable in the java script function.How can i pass this variable to apex controller and when i click on save i am passing the param value to apex controller.So when i click on save both param value and var in the javascript should be present in my apex class?How can i achieve this?
My Apex Class:
/** * ProgramMemberCaseAttachment * Created By: Varun * Created On: 11/07/2017 * Description: This class is responsible for displaying Attachment Details Under Each Program Member * **/ public with sharing class ProgramMemberCaseAttachment{ public string AttType{get;set;} public Id Attid{get;set;} public List<Attachment_Type__c> PMresults{get;set;} public Program_Member_MVN__c cs; public ProgramMemberCaseAttachment(ApexPages.StandardController controller) { cs=(Program_Member_MVN__c)controller.getRecord(); List<case> Test = new List<case>([select id from case where Program_Member_MVN__c =: cs.id]); System.debug('Test:'+Test); List<String> Id = new List<String>(); for(case Cs1 : Test){ Id.add(Cs1.id); } PMresults = [select Program_Memeber_Id__c,Id,Attachement_Name__c,Attachment_Description__c,Name,Type__c from Attachment_Type__c where Program_Memeber_Id__c =: cs.id OR Program_Memeber_Id__c IN: Id]; System.debug('PMresults '+PMresults ); } public void processSelected1(){ AttType = System.currentPageReference().getParameters().get('Mahavir'); System.debug('AttType '+AttType ); } public void processSelected(){ System.debug('AttType 1'+AttType ); List<Attachment_Type__c> PMType = new List<Attachment_Type__c>(); Attachment_Type__c At1 = new Attachment_Type__c (); At1 = [select Type__c from Attachment_Type__c where Program_Memeber_Id__c =: Attid]; System.debug('At1 '+At1 ); if(At1.Type__c != null){ At1.Type__c = AttType ; } PMType.add(At1); set<Attachment_Type__c> dedupSet = new set<Attachment_Type__c>(); dedupSet.addAll(PMType); List<Attachment_Type__c> dedupList = new List<Attachment_Type__c>(); dedupList.addAll(dedupSet); System.debug('dedupList'+dedupList); Update dedupList; } }