Hi,
I am new to programming and PHP and need some help converting this client side page to a server side PHP page. Here's what I have to convert: Script to be executed - document.write ("<table ><table class=ctable width=50% border='0'>");
-
document.write ("<tr>","<td>");
-
document.write ("<form name=first>");
-
document.write ("<table class=ctable>");
-
document.write ("<tr>","<td>Loan Amount:</td>","<td><input name=aa type=text size=15
-
-
onkeyup=checnum(this) ></td>","</tr>");
-
document.write ("<tr>","<td>Interest Rates:</td>","<td><input name=bb type=text size=15
-
-
onkeyup=checnum(this) ></td>","</tr>");
-
document.write ("<tr>","<td>Term(Years):</td><td><input name=cc type=text size=15
-
-
onkeyup=checnum(this)></td>","</tr>");
-
document.write ("</table>");
-
document.write ("<br>");
-
document.write ("<input type=button name=ss value=calculate onclick=loan() class=calc>");
-
document.write ("<br>");
-
-
function checnum(as)
-
{
-
var dd = as.value;
-
if(isNaN(dd))
-
{
-
dd = dd.substring(0,(dd.length-1));
-
as.value = dd;
-
}
-
}
-
function loan()
-
{
-
var a = document.first.aa.value;
-
var b = document.first.bb.value;
-
var c = document.first.cc.value;
-
var n = c * 12;
-
var r = b/(12*100);
-
var p = (a * r *Math.pow((1+r),n))/(Math.pow((1+r),n)-1);
-
var prin = Math.round(p*100)/100;
-
document.first.r1.value = prin;
-
var mon = Math.round(((n * prin) - a)*100)/100;
-
document.first.r2.value = mon;
-
var tot = Math.round((mon/n)*100)/100;
-
document.first.r3.value = tot;
-
for(var i=0;i<n;i++)
-
{
-
var z = a * r * 1;
-
var q = Math.round(z*100)/100;
-
var t = p - z;
-
var w = Math.round(t*100)/100;
-
var e = a-t;
-
var l = Math.round(e*100)/100;
-
a=e;
-
}
-
}
-
-
-
document.write ("<br>");
-
document.write ("<table class=ctable border=1 cellspacing=0 cellpadding=3>");
-
-
document.write ("<tr>","<th>Payment</th>","<th>Total Interest Paid</th>","<th>Monthly
-
-
Interest</th>","</tr>");
-
document.write ("<tr>","<td> <input name=r1 type=text readonly > </td>","<td> <input
-
-
name=r2 type=text readonly ></td>","<td> <input name=r3 type=text readonly > </td>","</tr>");
-
document.write ("</td>","</tr>");
-
document.write ("</table>","</form>");
-
document.write ("</table>");
-
-
- Main PHP Page
-
-
<?php echo '<?xml version="1.0" encoding="IUTF-8"?>'; ?>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org" />
-
-
<title></title>
-
<body>
-
-
<script src="table.js" type="text/javascript">
-
</script>
-
-
</body>
-
</html>
5 2118
There's no point to all the document.write calls. Just use the HTML directly.
You can't do an onkeyup event without javascript but you can do the validation on the server side if you want. It's not as responsive as javascript but if you can't use any javascript, that's the only option you have.
As for calculating the loan, submit the loan data to either itself or a different page to display the results. The option is up to you.
Well, I want to have the tables created dynamically, so that's why there are so many document.write. I know php uses the print function, so would I just replace the document.write with the print function? What I want to do is have the table with the calculations appear after the button is pressed. Does that make since? I'm just not sure where to start. Would you be able to give an example of how to do some of this?
If you're not sure where to start, then you need to start with a PHP tutorial. I recommend this one from w3schools: http://w3schools.com/php/.
You can't do "dynamic" with PHP. At least not in the same fashion as javascript. With PHP, you have to submit the data to a PHP page which returns a new page to display.
Thanks for the help. I think I got it. It all seems to work, so I'm going with it. :) This is what I have come up with: - table.class
-
-
<?php
-
$pay = round(calculatePayment($balance,$rate,$term),2);
-
echo "<tr><th colspan='2' align='center'>Here's Your Estimated Monthly Payment</th></tr>";
-
echo "<tr><td class='res'> Monthly Payments </td><td> $".$pay."</td></tr>";
-
echo "<tr><td class='res'>Interest Paid</td><td> $".(($term*$pay*$period)-$balance)."</td></tr>";
-
echo "<tr><td class='res'>Loan Term</td><td>".$term." Years</td></tr>";
-
?>
-
- calculator.class
-
-
<?php
-
$period = 12;
-
-
function calculatePayment($balance,$rate,$term){
-
global $period;
-
-
$N = $term * $period;
-
$I = ($rate/100)/$period;
-
$v = pow((1+$I),$N);
-
$t = ($I*$v)/($v-1);
-
$result = $balance*$t;
-
-
return $result;
-
}
-
-
$balance = isset($_POST['balance']) ? $_POST['balance'] : '';
-
$rate = isset($_POST['rate']) ? $_POST['rate'] : '';
-
$term = isset($_POST['term']) ? $_POST['term'] : '';
-
-
?>
-
- Page
-
-
<body>
-
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
-
<div class="CSSTable" ><table>
-
<tr><td>Loan Amount:</td><td><input class="text" name="balance" type="text" size="15" value="<?php echo $balance; ?>" /> $</td></tr>
-
<tr><td>Interest rate:</td><td> <input class="text" name="rate" type="text" size="5" value="<?php echo $rate; ?>" /> %</td></tr>
-
<tr><td>Loan term:</td><td> <input class="text" name="term" type="text" size="5" value="<?php echo $term; ?>" /> years</td></tr>
-
<tr><td align="center" colspan="2"><br/><input class="text" type="submit" name="submitBtn" value="Calculate" /></td></tr>
-
</table>
-
</form>
-
<?php
-
if ((isset($_POST['submitBtn']) && ($balance != '') && ($rate != '') && ($term != ''))){
-
?>
-
<table class="CSSTable">
-
<?php
-
require_once('class/table.class.php');
-
?>
-
</table>
-
-
</div>
-
<?php
-
}
-
?>
-
</body>
Glad you got it working, good luck with the rest of your project.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sebastien B. |
last post by:
I'm looking for the best tool to convert 'every day' html into proper XHTML
so that I can parse it as an XML document.
So far I've been using Tidylib to do this, but it doesn't handle things as...
|
by: Zhao Sheng |
last post by:
http://www.guangmingsoft.com/htmltoimage/help.htm
Html To Image
Html To Image 2.0 Released!
Html To Image help you convert html page from any URL to image or
thumbnails easily and quickly.
...
|
by: Stephen Miller |
last post by:
I have an ASPX report and I want to capture the rendered HTML and
write to a file on the webserver. Several posts suggest using
WebRequest to make a second call to the page, and screen-scrape the...
|
by: vaidas gudas |
last post by:
how to convert HTML page to XML format
|
by: PenguinPig |
last post by:
Dear All Experts
I would like to know how to convert a HTML into Image using C#. Or allow me
contains HTML code (parsed) in Image? I also tried this way but it just
display the character "<" &...
|
by: fjanon |
last post by:
Is there a way to remove the default footer/header from the printed
page when printing a page from HTML/Javascript in IE 6? I want to use
letterhead paper and I have to remove manually the...
|
by: Class |
last post by:
Hi all,
I am looking for some .NET code which can convert HTML to a PDF.
I have looked the internet bad without any luck so far.
I have found the iText.NET this has alot of sample but couldn't...
|
by: Damiano |
last post by:
Hello,
How could i convert Html page in a PDF file?
Is there a free library?
Thanks
|
by: meenanarayanan |
last post by:
Hi,
I am new to jasper.I need to convert a jsp page into PDF in jasper.I am getting values from the database in the jsp page.The jsp page will display the values in the table format.The...
|
by: Arsale |
last post by:
I am trying to pass a javascript variable to php on javascript generated page, but on the new page I got only "Array". Where did I go wrong?
On first page, i've got image map with areas....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |