• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 63
  • Last Modified:

Calling Java Script Function Into smarty tpl

<script type="text/javascript">
 {literal}
        function emi()
        {
                var P = $smarty.capture.$clean_price; // pick the form input value..
                var rate = 14; // pick the form input value..
                var n = 12; // pick the form input value..
                var r = rate/(12*100); // to calculate rate percentage..
                var prate = (P * r * Math.pow((1+r),n))/(Math.pow((1+r),n)-1); // to calculate compound interest..
                var emi = Math.ceil(prate * 100) / 100; // to parse emi amount..
        // to assign value in field1 as fixed upto two decimal..
                var finalemi= emi.toFixed();
                
        //to assign value in field2..   
                var tot = Math.round(document.formval.field1.value * n * 100)/100; // to calculate total amount
                document.formval.field2.value = Math.abs(tot);
        // to assign value in field3..  
                var int_amt = document.formval.field2.value - P; // to calculate net interest amount
                document.formval.field3.value =  int_amt.toFixed(2);
        } 
         
         {/literal}
        </script> 
             <a href="javascript:void();" onclick="javascript:emi()" title="Emi From"></a>

Open in new window

0
vikas saraswat
Asked:
vikas saraswat
1 Solution
 
CEHJCommented:
Posting JavaScript questions in the Java TA is not appropriate, and might make your question less likely to be answered. http://technojeeves.com/joomla/index.php/free/127-javascript-is-not-java
0
 
Ray PaseurCommented:
Please post the SSCCE so we can copy and paste the code into a script on our own servers.  Then we can see the exact failure you're seeing and we can discuss the reasons and solutions.

Please use the Code Snippet feature.  Thanks.
0
 
leakim971PluritechnicianCommented:
You're not limited to one set of {literal}{/literal}
So you can do :
<script type="text/javascript">
{literal}
        function emi()
        {
                var P = {/literal}$smarty.capture.$clean_price{literal}; // pick the form input value..
                var rate = 14; // pick the form input value..
                var n = 12; // pick the form input value..
                var r = rate/(12*100); // to calculate rate percentage..
                var prate = (P * r * Math.pow((1+r),n))/(Math.pow((1+r),n)-1); // to calculate compound interest..
                var emi = Math.ceil(prate * 100) / 100; // to parse emi amount..
        // to assign value in field1 as fixed upto two decimal..
                var finalemi= emi.toFixed();
                
        //to assign value in field2..   
                var tot = Math.round(document.formval.field1.value * n * 100)/100; // to calculate total amount
                document.formval.field2.value = Math.abs(tot);
        // to assign value in field3..  
                var int_amt = document.formval.field2.value - P; // to calculate net interest amount
                document.formval.field3.value =  int_amt.toFixed(2);
        } 
         
{/literal}
</script> 
<a href="javascript:void();" onclick="javascript:emi()" title="Emi From"></a>

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now