Find your content:

Search form

You are here

javascript for dom ready function

 
Share

My visualforce 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:inputtext Value="{!item.Quantity__c}" onblur="multiplycal();" styleclass="quantity{!rowNum}"/>**
                  </apex:column>
                   <apex:column headerValue="Unit Price($)">
                     <apex:inputtext 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>      

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));
    }

    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];
}
</script>

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 https://salesforce.stackexchange.com/questions/5001

My Block Status

My Block Content