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
ravi yadav 34ravi yadav 34 

Hi every one,can anyone help me for this scenario..Following is my code

controller:
public class ProjectScenario {
    // To display the list of AQ_LineItem__cS
    public list<AQ_LineItem__c>AQ_lineItemList {set;get;}
    //To get the current opportunityId.
    public Id AQId {set;get;}
    // To get the record Id which is editing in visualforcePage.
    public String rId{get;set;}
    public AQ_LineItem__c  Obj_AQLineItem = new AQ_LineItem__c();
    public AQ_LineItem__c  Obj_AQLineItem1 = new AQ_LineItem__c();
    public ProjectScenario(apexpages.StandardController controller){
        AQId = controller.getId();
        system.debug('AQId===>'+AQId);
        AQ_lineItemList =[select id,PictureUrl__c,Name,AQ_Quantity__c,AQ_NetPrice__c,AQ_SellPrice__c,
                          (select id,Name,AQ_Quantity__c,AQ_NetPrice__c,AQ_SellPrice__c from AQ_SubLineItems__r)
                          from AQ_LineItem__c where Project__c=:AQId];
        system.debug('AQ_lineItemList project'+AQ_lineItemList);
    }
    public void CalculateTotal(){
        Obj_AQLineItem = [select id,AQ_Quantity__c,AQ_NetPrice__c,AQ_SellPrice__c from AQ_LineItem__c  where id =:rId];
        system.debug('Obj_AQLineItem===>'+Obj_AQLineItem.AQ_Quantity__c);
        Obj_AQLineItem1=[select id,AQ_Quantity__c,AQ_NetPrice__c,AQ_SellPrice__c from AQ_LineItem__c where id=:Obj_AQLineItem.Id];
        system.debug('Obj_AQLineItem1===>'+Obj_AQLineItem1.AQ_Quantity__c);
        Obj_AQLineItem1.AQ_SellPrice__c=Obj_AQLineItem1.AQ_Quantity__c*Obj_AQLineItem1.AQ_NetPrice__c;
    }
}

visualforcepage:
<apex:page standardController="opportunity" extensions="ProjectScenario" id="page" sidebar="false" showHeader="false" setup="false">
    <style>
        #customers {
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        border-collapse: collapse;
        width: 100%;
        }
       
        #customers td, #customers th {
        border: 1px solid #ddd;
        padding: 8px;
        }
       
        #customers tr:nth-child(even){background-color: #f2f2f2;}
       
        #customers tr:hover {background-color: #ddd;}
       
        #customers th {
        padding-top: 12px;
        padding-bottom: 12px;
        text-align: left;
        background-color: #4CAF50;
        color: white;
        }
    </style>
    <style>
        #customers1 {
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        border-collapse: collapse;
        width: 100%;
        }
       
        #customers1 td, #customers th {
        border: 1px solid #ddd;
        padding: 8px;
        }
       
        #customers1 tr:nth-child(even){background-color: #f2f2f2;}
       
        #customers1 tr:hover {background-color: #ddd;}
       
        #customers1 th {
        padding-top: 12px;
        padding-bottom: 12px;
        text-align: left;
       
        }
    </style>
    <apex:form id="fm">
        <apex:pageBlock id="pb">
            <table id="customers1">
                <tr>
                    <th style="background-color: #4CAF50;">Name</th>
                    <th>{!opportunity.Name}</th>
                </tr>
                <tr>
                    <th style="background-color: #4CAF50;">Amount</th>
                </tr>
                <tr>
                    <th style="background-color: #4CAF50;">CloseDate</th>
                    <th>{!opportunity.CloseDate}</th>
                </tr>
            </table><br/><br/>
            <table id="customers">
                <tr>
                    <th>Image</th>
                    <th>Name</th>
                    <th>AQ_Quantity__c</th>
                    <th>AQ_NetPrice__c</th>
                    <th>AQ_SellPrice__c</th>
                </tr>
                <apex:repeat value="{!AQ_lineItemList}" var="r" id="pbt">
                    <tr>
                        <td><apex:image id="theImage" value="{!r.PictureUrl__c}" width="55" height="55" alt="Description of image here"/></td>
                        <td><apex:outputField value="{!r.Name}"/></td>
                        <td><apex:inputtext value="{!r.AQ_Quantity__c}">
                            <apex:actionSupport event="onchange" action="{!CalculateTotal}" reRender="pbt">
                                <apex:param name="rId" value="{!r.Id}" assignTo="{!rId}"/>
                            </apex:actionSupport>
                            </apex:inputtext></td>
                        <td><apex:outputField value="{!r.AQ_NetPrice__c}"/></td>
                        <td><apex:outputfield value="{!r.AQ_SellPrice__c}"/></td>
                    </tr>
                    <apex:repeat value="{!r.AQ_SubLineItems__r}"  var="T" id="pbt1">
                        <tr>
                            <td></td>
                            <td><apex:outputField value="{!T.Name}"/></td>
                            <td><apex:inputtext value="{!T.AQ_Quantity__c}"/></td>
                            <td><apex:outputField value="{!T.AQ_NetPrice__c}"/></td>
                            <td><apex:outputField value="{!T.AQ_SellPrice__c}"/></td>
                        </tr>
                    </apex:repeat>
                </apex:repeat>
            </table>
        </apex:pageBlock>
    </apex:form>
</apex:page>

I am not able getting onchange value in the quantity field..I am getting the value which is already in the database..but now i want to get value onchange event..

thanks..
SubhamSubham
In this case, I would use Pass (This.id) through onchange to a javascript function and use Document.getElementbyId to fetch the value input by user.
Once you have the value then call your action though actionfunction.
 
Gaurav HandooGaurav Handoo
Hi Ravi

Following is the VF code you can use:
 
<apex:page standardController="opportunity" extensions="ProjectScenario" id="page" sidebar="false" showHeader="false" setup="false">
    <script type="text/javascript">
    	function calculateTotalVF()
    	{
    		CalculateTotal();
    	}
    </script>
    <style>
        #customers {
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        border-collapse: collapse;
        width: 100%;
        }
       
        #customers td, #customers th {
        border: 1px solid #ddd;
        padding: 8px;
        }
       
        #customers tr:nth-child(even){background-color: #f2f2f2;}
       
        #customers tr:hover {background-color: #ddd;}
       
        #customers th {
        padding-top: 12px;
        padding-bottom: 12px;
        text-align: left;
        background-color: #4CAF50;
        color: white;
        }
    </style>
    <style>
        #customers1 {
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        border-collapse: collapse;
        width: 100%;
        }
       
        #customers1 td, #customers th {
        border: 1px solid #ddd;
        padding: 8px;
        }
       
        #customers1 tr:nth-child(even){background-color: #f2f2f2;}
       
        #customers1 tr:hover {background-color: #ddd;}
       
        #customers1 th {
        padding-top: 12px;
        padding-bottom: 12px;
        text-align: left;
       
        }
    </style>
    <apex:form id="fm">
    <apex:actionFunction name="CalculateTotal" action="{!CalculateTotal}"/>
        <apex:pageBlock id="pb">
            <table id="customers1">
                <tr>
                    <th style="background-color: #4CAF50;">Name</th>
                    <th>{!opportunity.Name}</th>
                </tr>
                <tr>
                    <th style="background-color: #4CAF50;">Amount</th>
                </tr>
                <tr>
                    <th style="background-color: #4CAF50;">CloseDate</th>
                    <th>{!opportunity.CloseDate}</th>
                </tr>
            </table><br/><br/>
            <table id="customers">
                <tr>
                    <th>Image</th>
                    <th>Name</th>
                    <th>AQ_Quantity__c</th>
                    <th>AQ_NetPrice__c</th>
                    <th>AQ_SellPrice__c</th>
                </tr>
                <apex:repeat value="{!AQ_lineItemList}" var="r" id="pbt">
                    <tr>
                        <td><apex:image id="theImage" value="{!r.PictureUrl__c}" width="55" height="55" alt="Description of image here"/></td>
                        <td><apex:outputField value="{!r.Name}"/></td>
                        <--<td><apex:inputtext value="{!r.AQ_Quantity__c}">-->
                        <apex:inputtext value="{!r.AQ_Quantity__c}" onchange="calculateTotalVF()">
                            <!--<apex:actionSupport event="onchange" action="{!CalculateTotal}" reRender="pbt">
                                <apex:param name="rId" value="{!r.Id}" assignTo="{!rId}"/>
                            </apex:actionSupport>-->
                            </apex:inputtext></td>
                        <td><apex:outputField value="{!r.AQ_NetPrice__c}"/></td>
                        <td><apex:outputfield value="{!r.AQ_SellPrice__c}"/></td>
                    </tr>
                    <apex:repeat value="{!r.AQ_SubLineItems__r}"  var="T" id="pbt1">
                        <tr>
                            <td></td>
                            <td><apex:outputField value="{!T.Name}"/></td>
                            <td><apex:inputtext value="{!T.AQ_Quantity__c}"/></td>
                            <td><apex:outputField value="{!T.AQ_NetPrice__c}"/></td>
                            <td><apex:outputField value="{!T.AQ_SellPrice__c}"/></td>
                        </tr>
                    </apex:repeat>
                </apex:repeat>
            </table>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Hope this helps. Please mark as best answer if it does.

Cheers!!

Gaurav