Solved

Joomla Article Java

Posted on 2010-09-16
6
511 Views
Last Modified: 2012-06-21
Hi Experts,

I have a Java based calculator that works fine in regular html pages but when I place behind an article (toggle editor mode) it doesn't work so well.  It renders fine but the buttons don't do anything.

How can I place script like this in an article body and have the calculator buttons function properly?

Thanks,

HNM
<div id="loanCalculatorContainer">

				

				<script language-="javascript">



<!--







var newWindow;



     



function makeNewWindow() {



	newWindow = window.open("", "", "menubar,status,scrollbars,height=375,width=325")



	}







function roundtopennies(n)



{



	pennies = n * 100;



	pennies = Math.round(pennies);



	



	strpennies = "" + pennies;



	len = strpennies.length;







	return strpennies.substring(0, len - 2) + "." + strpennies.substring(len - 2, len);



}











function monthly(principal, years, apr)



{







	rate = apr / 12;



	payments = years *12;



	return roundtopennies(principal * rate / (1 - (1 / Math.pow(1 + rate, payments))));



}







function monthlyamortization2(principal, years, apr)



{



	var interestpayment; var principalpayment; var i;



	var payments = years * 12;



	var monthlyinterest = apr /12;



	var monthlypayment = monthly(principal, years, apr);



	var rndprincipal = roundtopennies(principal);



	var monthpayment = monthly(principal, years, apr);



	var totinterest = 0; var totpayments= 0;



	var rndintpayment;



	var rndprncppayment;



	var rndprincipal;



	



	var pennies1, pennies2, pennies3, strpennies1, strpennies2, strpennies3, len1, len2, len3;







	makeNewWindow();	



	newWindow.document.write("<center>");	



	newWindow.document.write("<font face=Verdana, Arial, Helvetica, sans-serif size=2>");



	newWindow.document.write("<font color=cc9900>");			



	newWindow.document.write("<h2>Monthly Payments</h2>");



	newWindow.document.write("</font>");	



	newWindow.document.write("<table border>");	



	newWindow.document.write("<tr>");



	newWindow.document.write("<th colspan=4>");



	newWindow.document.write("<br>$" + (rndprincipal));



	newWindow.document.write(" at " + (apr));



	newWindow.document.write(" over " + years + " years.<br><br>");



	newWindow.document.write("Monthly payment= $" + (monthpayment));



	newWindow.document.write("<br><br>");



	newWindow.document.write("</th>");



	newWindow.document.write("</tr>");



	







		



for(i = 1; i <= payments; i++)



{











	interestpayment = principal * monthlyinterest;



	pennies1 = interestpayment * 100;



	pennies1 = Math.round(pennies1);



	strpennies1 = "" + pennies1;



	len1 = strpennies1.length;



	rndintpayment= strpennies1.substring(0, len1 - 2) + "." + strpennies1.substring(len1 - 2, len1);







	



	principalpayment = monthlypayment - interestpayment;



	pennies2 = principalpayment * 100;



	pennies2 = Math.round(pennies2);



	strpennies2 = "" + pennies2;



	len2 = strpennies2.length;



	rndprncppayment= strpennies2.substring(0, len2 - 2) + "." + strpennies2.substring(len2 - 2, len2);







	



	principal -= principalpayment;



	pennies3 = principal * 100;



	pennies3 = Math.round(pennies3);



	strpennies3 = "" + pennies3;



	len3 = strpennies3.length;



	rndprincipal= strpennies3.substring(0, len3 - 2) + "." + strpennies3.substring(len3 - 2, len3);







	







	totinterest= totinterest + interestpayment;



	totpayments= totpayments + interestpayment + principalpayment;



}



	



	pennies3 = totinterest * 100;



	pennies3 = Math.round(pennies3);



	strpennies3 = "" + pennies3;



	len3 = strpennies3.length;



	totinterest= strpennies3.substring(0, len3 - 2) + "." + strpennies3.substring(len3 - 2, len3);



	



	pennies3 = totpayments * 100;



	pennies3 = Math.round(pennies3);



	strpennies3 = "" + pennies3;



	len3 = strpennies3.length;



	totpayments= strpennies3.substring(0, len3 - 2) + "." + strpennies3.substring(len3 - 2, len3);











newWindow.document.write("</table>");



newWindow.document.write("<br>The total amount of interest paid<br>would be $" + eval(totinterest) + "<br><br>");



newWindow.document.write("The total amount of payments paid<br>would be $" + eval(totpayments) + ".<br><br><br>");



newWindow.document.write("<font color=cc0000>");



newWindow.document.write("These figures are intended for information audit purposes only.<br><br>");



newWindow.document.write("</font>");



newWindow.document.write("</font>");



newWindow.document.write("</center>");



newWindow.document.close();



}















function monthlyamortization(principal, years, apr)



{



	var interestpayment; var principalpayment; var i;



	var payments = years * 12;



	var monthlyinterest = apr /12;



	var monthlypayment = monthly(principal, years, apr);



	var rndprincipal = roundtopennies(principal);



	var monthpayment = monthly(principal, years, apr);



	var totinterest = 0; var totpayments= 0;



	var rndintpayment;



	var rndprncppayment;



	var rndprincipal;



	



	var pennies1, pennies2, pennies3, strpennies1, strpennies2, strpennies3, len1, len2, len3;







	makeNewWindow();



	newWindow.document.write("<center>");	



	newWindow.document.write("<font face=Verdana, Arial, Helvetica, sans-serif size=2>");



	newWindow.document.write("<font color=cc9900>");	



	newWindow.document.write("<h2>Amortization Table</h2>");



	newWindow.document.write("Please wait for this table to compute.<br><br>");



	newWindow.document.write("</font>");



	newWindow.document.write("<table border>");	



	newWindow.document.write("<tr>");



	newWindow.document.write("<th colspan=4>");



	newWindow.document.write("<br>$" + (rndprincipal));



	newWindow.document.write(" at " + (apr));



	newWindow.document.write(" over " + years + " years.<br><br>");



	newWindow.document.write("Monthly payment= $" + (monthpayment));



	newWindow.document.write("<br><br>");



	newWindow.document.write("</th>");



	newWindow.document.write("</tr>");



	



	newWindow.document.write("<tr>");



	newWindow.document.write("<th></th>");



	newWindow.document.write("<th colspan=2>Payment</th>");



	newWindow.document.write("</tr>");



	



	newWindow.document.write("<tr>");



	newWindow.document.write("<th>Month</th>");



	newWindow.document.write("<th>Interest</th>");



	newWindow.document.write("<th>Principal</th>");



	newWindow.document.write("<th>Balance</th>");



	newWindow.document.write("</tr>");



		



for(i = 1; i <= payments; i++)



{



	newWindow.document.write("<tr>");



	newWindow.document.write("<td>" + i + "</td>");







	interestpayment = principal * monthlyinterest;



	pennies1 = interestpayment * 100;



	pennies1 = Math.round(pennies1);



	strpennies1 = "" + pennies1;



	len1 = strpennies1.length;



	rndintpayment= strpennies1.substring(0, len1 - 2) + "." + strpennies1.substring(len1 - 2, len1);



	newWindow.document.write("<td>$" + (rndintpayment) + "</td>");



	



	principalpayment = monthlypayment - interestpayment;



	pennies2 = principalpayment * 100;



	pennies2 = Math.round(pennies2);



	strpennies2 = "" + pennies2;



	len2 = strpennies2.length;



	rndprncppayment= strpennies2.substring(0, len2 - 2) + "." + strpennies2.substring(len2 - 2, len2);



	newWindow.document.write("<td>$" + (rndprncppayment) + "</td>");



	



	principal -= principalpayment;



	pennies3 = principal * 100;



	pennies3 = Math.round(pennies3);



	strpennies3 = "" + pennies3;



	len3 = strpennies3.length;



	rndprincipal= strpennies3.substring(0, len3 - 2) + "." + strpennies3.substring(len3 - 2, len3);



	newWindow.document.write("<td>$" + (rndprincipal) + "</td>");



	



	newWindow.document.write("</td>");



	totinterest= totinterest + interestpayment;



	totpayments= totpayments + interestpayment + principalpayment;



}



	



	pennies3 = totinterest * 100;



	pennies3 = Math.round(pennies3);



	strpennies3 = "" + pennies3;



	len3 = strpennies3.length;



	totinterest= strpennies3.substring(0, len3 - 2) + "." + strpennies3.substring(len3 - 2, len3);



	



	pennies3 = totpayments * 100;



	pennies3 = Math.round(pennies3);



	strpennies3 = "" + pennies3;



	len3 = strpennies3.length;



	totpayments= strpennies3.substring(0, len3 - 2) + "." + strpennies3.substring(len3 - 2, len3);











newWindow.document.write("</table>");



newWindow.document.write("<br>The total amount of interest paid<br>would be $" + eval(totinterest) + "<br><br>");



newWindow.document.write("The total amount of payments paid<br>would be $" + eval(totpayments) + "<br><br><br>");



newWindow.document.write("<font color=cc0000>");



newWindow.document.write("These figures are intended for information audit purposes only and not to be considered for payout purposes.<br><br>");



newWindow.document.write("</font>");



newWindow.document.write("</font>");



newWindow.document.write("</center>");



newWindow.document.close();



}







function compute(form)



{



	if((form.principal.value.length != 0) && (form.apr.value.length != 0) && (form.years.value.length != 0))



	{



		principal = eval(form.principal.value);



		apr= eval(form.apr.value) / 100.0;



		years = eval(form.years.value);



		



		if (years == 0.0)



		{



			alert("You have no monthly payment, since the # of years is 0.");



		}



		else



		{



			monthlyamortization(principal, years, apr);



		}



	}



	else



	{



		alert("You must fill in all the fields if you want a response from me!!");



	}



}







function payment(form)



{



	if((form.principal.value.length != 0) && (form.apr.value.length != 0) && (form.years.value.length != 0))



	{



		principal = eval(form.principal.value);



		apr= eval(form.apr.value) / 100.0;



		years = eval(form.years.value);



		



		if (years == 0.0)



		{



			alert("You have no monthly payment, since the # of years is 0.");



		}



		else



		{



			monthlyamortization2(principal, years, apr);



		}



	}



	else



	{



		alert("You must fill in all the fields if you want a response from me!!");



	}



}















// -->



</script>











      



      



      



      <blockquote>



        <div align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="4" color="#003566"><b>Loan 



          Calculator:</b></font></div>



        <form name="">



          <center>



            <table width="85%" border="0" cellspacing="0" cellpadding="0">



              <tr align="center"> 



                <td> 



                  <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">do 



                    not use commas or spaces</font></b><br>



                  </div>



                  <table border=1 bordercolor="#666666" cellpadding="5">



                    <tr bgcolor="#FFCC66" align="right"> 



                      <td valign="middle" bgcolor="#FFCC66"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Loan 



                        Amount:</font></b></td>



                      <td valign="middle" bgcolor="#FFCC66"> <b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">$</font></b> 



                        <input type=text name=principal size="6">



                        <b><font color="#FFCC66" face="Verdana, Arial, Helvetica, sans-serif" size="2">%</font></b> 



                      </td>



                    </tr>



                    <tr bgcolor="#336699" align="right"> 



                      <td valign="middle"><b><font color="#FFFFFF" face="Verdana, Arial, Helvetica, sans-serif" size="2">Interest 



                        Rate:</font></b></td>



                      <td valign="middle" bgcolor="#336699"> 



                        <input type=text name=apr size="5">



                        <b><font color="#FFFFFF" face="Verdana, Arial, Helvetica, sans-serif" size="2">%</font></b> 



                      </td>



                    </tr>



                    <tr bgcolor="#FFCC66" align="right"> 



                      <td valign="middle"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Number 



                        of Years:</font></b></td>



                      <td valign="middle"> 



                        <input type=text name=years size="5">



                        <b><font color="#FFCC66" face="Verdana, Arial, Helvetica, sans-serif" size="2">%</font></b> 



                      </td>



                    </tr>



                    <tr bgcolor="#336699"> 



                      <td valign="middle" bgcolor="#336699"> 



                        <input type=button value=" Amortization Table " onClick="compute(this.form)" name="button">



                      </td>



                      <td valign="middle"> 



                        <input type= button value=" Monthly Payments " onClick="payment(this.form)" name="button2">



                      </td>



                    </tr>



                  </table>



                </td>



              </tr>



            </table>



            <p><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#CC0000">These 



              figures are intended for information audit purposes only.</font> 



              <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#CC0000"><b><br>



              Warning:</b></font><font face="Verdana, Arial, Helvetica, sans-serif" size="1"> 



              some computers may have difficulty computing large sums amortized 



              over many years. </font> </p>



          </center>



        </form>



        <blockquote>           



                </blockquote>



    </td>



  </tr>



              <blockquote>



        <p align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#003566">&copy; 



          Test Inc.<br>



          </font></p>



      </blockquote>



</table>

Open in new window

0
Comment
Question by:HelpNearMe
  • 4
6 Comments
 
LVL 11

Accepted Solution

by:
Amanda Watson earned 350 total points
Comment Utility
The best way to achieve this would be to insert all of that code into a custom html module within joomla.

Does your site have a custom html module already installed under the module manager?

If so you copy that code, paste it into the html part of the custom module and publish your module where you want the calculator to appear!

0
 

Author Comment

by:HelpNearMe
Comment Utility
Good point, I am already using the custom module in other areas... didn't consider it for this application.

I'll try it.

Thanks,

HNM
0
 
LVL 11

Expert Comment

by:Amanda Watson
Comment Utility
Great, let me know how it goes! ;-)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 10

Assisted Solution

by:fearialtog
fearialtog earned 150 total points
Comment Utility
You could install an extension like the one below. Then your code would run in the content as well and not just be confined to a module position.


http://extensions.joomla.org/extensions/edition/custom-code-in-content/5051

Full list of extensions for placing custom code in Joomla
http://extensions.joomla.org/extensions/edition/custom-code-in-content
0
 
LVL 11

Expert Comment

by:Amanda Watson
Comment Utility
There is also this thread that shows you how to add a module position in an article too

http://www.joomlaspan.com/general/include-any-module-within-content-in-joomla-15.php

This I find useful too
0
 
LVL 11

Expert Comment

by:Amanda Watson
Comment Utility
To fix that issue, you turn the Editor off (in global configuration) and then enter in the code.

You can also use the mod html which leaves all the code within without stripping or adding anything like the custom html module can
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Since I am currently running into this issue right now as I type this, I though I would share my experiences with moving a ModX Revolution site from one server to another.  It is not an easy task, but can be accomplished rather easily. The first …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 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

9 Experts available now in Live!

Get 1:1 Help Now