Find your content:

Search form

You are here

javascript for dom ready function


My visualforce page is

 <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:inputtext Value="{!item.Quantity__c}" onblur="multiplycal();" styleclass="quantity{!rowNum}"/>**
                   <apex:column headerValue="Unit Price($)">
                     <apex:inputtext Value="{!item.Price__c}" styleClass="price{!rowNum}" onblur="multiplycal();"/>
           <input type="hidden" value="{!rowNum}" class="values" name="values"/>  
 <apex:pageBlockSectionItem >          
                     <apex:outputLabel value="total($) :"/>
                     <apex:outputLabel value="" styleClass="sum"  style="width:78px;text-align:right;display:block;font-size:12px;color:#000000;" />

My javascript is:

<script type="text/javascript">
var j$ = jQuery.noconflict();
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));


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];

If I use apex:inputtext it is working fine. But my requirement is <apex:outputlabel Value="{!item.Quantity__c}" onblur="multiplycal();" styleclass="quantity{!rowNum}"/>. for this I can't use onblur since I'm using apex:outputlabel. Hence I should go with dom ready function.But don't have any idea.Help!!!!!!

Attribution to: Eagerin Sf

Possible Suggestion/Solution #1

Well not sure what you want to do but if you want to hook to the dom ready you have to do something like this

var j$ = jQuery.noconflict(); 
j$(document).ready(function() {
   // put all your js in here.

Attribution to: Avidev9
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content