2

my javascript is

function multiplycal(){
          var values=$(".values").val();  
          var total = 0.0;

         for(var i=0;i<values;i++)
         {
            var amtfield=trim($(".price"+i).val());       
            var quantity=trim($(".quantity"+i).val());
            total= parseFloat(total)+(parseFloat(amtfield) * parseInt(quantity));

         }

         alert(total);
            $('.sum').html(formatDoll(total));
        }

     function formatDoll(number) {
        var pip = number.toFixed(2).split(".");
        return pip[0].split("").reverse().reduce(function(acc, number, i, orig) {
            return  number+ (i && !(i % 3) ? "," : "") + acc;
        }, "") + "." + pip[1];
    }

and my Vf Page is

<apex:outputpanel>
 <apex:variable value="0" var="rowNum"/> 
      <apex:dataTable value="{!templook}" var="item" style="margin-left:60px;"  cellpadding="5" cellspacing="6"   >
 <apex:column headerValue="Quantity">
                      <apex:outputlabel Value="{!item.Quantity__c}" onblur="multiplycal();" styleclass="quantity{!rowNum}"/>
                  </apex:column>
                   <apex:column headerValue="Unit Price($)">
                     <apex:outputlabel Value="{!item.Price__c}" styleClass="price{!rowNum}" onblur="multiplycal();"/>
                  </apex:column>
  </apex:datatable>
           <input type="hidden" value="{!rowNum}" class="values" name="values"/>  
</apex:outputpanel>
 <apex:pageBlockSectionItem >          
                     <apex:outputLabel value="total($) :"/>
                     <apex:outputLabel value="" styleClass="sum"  style="width:78px;text-align:right;display:block;font-size:12px;color:#000000;" />
                     </apex:pageBlockSectionItem>          

now need to multiple price*quantity. Where I'm wrong?????? Any Suggestions are also welcomed

2
  • What is currently happening?
    – Mike Chale
    Nov 23, 2012 at 13:34
  • Nothing is Displaying....
    – Eagerin Sf
    Nov 23, 2012 at 13:46

3 Answers 3

1

Try adding a "no conflict" call to jQuery - this is pretty much mandatory for jQuery to work on a VisualForce page, as the '$' symbol is used by both the SalesForce and jQuery codebase. Put this at the bottom of your page:

<script>
j$ = jQuery.noConflict();
</script>

Then to call jQuery functions, use j$ rather than $.

0

Your JavaScript doesn't match your class names. You're looking for fields with classes of "price" and "quantity" but your Visualforce page is outputting price1, quantity1, price2, quantity2, etc . . .

Try removing the {!rowNum} merge fields.

2
  • then wat about my class="values" name="values".Where should I declare this
    – Eagerin Sf
    Nov 23, 2012 at 14:01
  • I would expect .values to work for that. Try walking through with a debugger like Firebug or alerts to check the variables. You can use debugger; to insert a breakpoint.
    – Mike Chale
    Nov 23, 2012 at 14:05
0

I believe your primary problem is that multiplycal() is called on blur of your apex:outputLabels.

That is a strange way to expect users to use your vf page. According to your code a user needs to put focus on the text produced by the outputLabel and then remove that focus for multiplycal() to be called. The multiplycal() function should probably be called on on dom ready e.g.

$(document).ready(function() {
  multiplycal();
});
1
  • sorry for the late reply....when I used the inputtext the onblur works great....but for outputlabel as you said it doesn't works.I never used the document function.can u be a bit more clear
    – Eagerin Sf
    Dec 3, 2012 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.