Solved

Calling Java Script Function Into smarty tpl

Posted on 2016-10-27
4
26 Views
Last Modified: 2016-11-24
<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
Comment
Question by:vikas saraswat
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 41863482
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41863669
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
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points (awarded by participants)
ID: 41875450
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now