Solved

Joomla Article Java

Posted on 2010-09-16
6
512 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
ID: 33696379
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
ID: 33696405
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
ID: 33696527
Great, let me know how it goes! ;-)
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 10

Assisted Solution

by:fearialtog
fearialtog earned 150 total points
ID: 33699205
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
ID: 33699263
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
ID: 33719892
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

808 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