Saturday, May 2, 2015

Multiplication calculator JQuery

<html>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <style>
        .schTable{}
        .noOfPay{}
        .amount{}
    </style>
    <body>
        <table class="schTable">
            <tr>
                <td> Total </td>
                <td id="totalId"> </td>
            </tr>
            <tr>
                <td>Input 1 </td>
                <td> Input 2 </td>
            </tr>
             <tr>
                <td><input type="text" class="noOfPay" onkeyup="calculateTotal();" /> </td>
                <td><input type="text" class="amount" onkeyup="calculateTotal();"/> </td>
            </tr>
             <tr>
                <td><input type="text" class="noOfPay" onkeyup="calculateTotal();"/> </td>
                <td><input type="text" class="amount" onkeyup="calculateTotal();"/> </td>
            </tr>
        </table>
    </body>
    <script>      
        var noOfPayArray = [];
        var amountArray = [];
        function calculateTotal(){  
            var i = 0;        
            $(".schTable .noOfPay").each(function( e ) {
               noOfPayArray[i] = $(this).val();
               i++;
            });
           
            i = 0;        
            $(".schTable .amount").each(function( e ) {                
                amountArray[i] = $(this).val();
                i++;
            });
            var total = 0.00;
            for(var i =0; i < amountArray.length; i++){              
               
                if(noOfPayArray[i] != '' && amountArray[i] != '' &&  noOfPayArray[i] != 'null' && amountArray[i] != 'null' && noOfPayArray[i] != null && amountArray[i] != null && !isNaN(noOfPayArray[i]) && !isNaN(amountArray[i])){
                 
                    total += parseFloat(noOfPayArray[i]) * parseFloat(amountArray[i]);
                }
            }
            document.getElementById('totalId').innerHTML = total.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");          
                   
        }      
    </script>
</html>

Salesforce - Generate dynamic inner query to fetch parent and related child records

Use Case: In many scenarios, we need to clone the records with related child records. Issue / Limitation: We may simply use the "cl...