Link to home
Start Free TrialLog in
Avatar of HelpNearMe
HelpNearMeFlag for Afghanistan

asked on

Joomla Article Java

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

ASKER CERTIFIED SOLUTION
Avatar of Amanda Watson
Amanda Watson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HelpNearMe

ASKER

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
Great, let me know how it goes! ;-)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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