Hi! I’m having problems with the php file i’m working on.
I’m supposed to make an html code work on php.
Here’s the html code:
[CODE]
<html>
<script type=”text/JavaScript”>
function calcATable()
{
aLoaned=document.getElementById(“aLoaned”).value;
i=document.getElementById(“iLoan”).value/100;
n=document.getElementById(“tLoan”).value;
annuity=(aLoaned*i)/(1-(1/Math.pow(1+i,n)));
document.getElementById(“payLoan”).value=parseInt(annuity*100)/100;
nB =”<table border=’1′>”;
nB+=” <tr>”;
nB+=” <td>Year</td>”;
nB+=” <td>Interest</td>”;
nB+=” <td>Principal</td>”;
nB+=” <td>Balance</td>”;
nB+=” <tr>”;
lBalance=aLoaned;
sumInterest=0;
sumPrincipal=0;
for (y=1; y<=n; y++)
{
aInterest=lBalance*i;
aPrincipal=annuity-aInterest;
lBalance-=aPrincipal;
sumInterest+=aInterest;
sumPrincipal+=aPrincipal;
nB+=” <tr>”;
nB+=” <td>”+y+”</td>”;
nB+=” <td align=’right’>”+parseInt(aInterest*100)/100+”</td>”;
nB+=” <td align=’right’>”+parseInt(aPrincipal*100)/100+”</td>”;
nB+=” <td align=’right’>”+parseInt(lBalance*100)/100+”</td>”;
nB+=” </tr>”;
}
nB+=” <tr>”;
nB+=” <td>Sum :</td>”;
nB+=” <td align=’right’>”+parseInt(sumInterest*100)/100+”</td>”;
nB+=” <td align=’right’>”+parseInt(sumPrincipal*100)/100+”</td>”;
nB+=” <td> </td>”;
nB+=” </tr>”;
nB+=”</table>”;
document.getElementById(“amortTable”).innerHTML=nB;
}
</script>
<body>
<div align=”center”>
<img src=”up.png”><br>
<b>ABC Bank of Tacloban</b>
</div><hr>
<table>
<caption>Loan Application Form<hr></caption>
<tr>
<td align=”right”>Name of borrower :</td>
<td><input type=”text” id=”nBorr” size=”30″></td>
</tr>
<tr>
<td align=”right”>Amount to be loaned :</td>
<td><input type=”text” id=”aLoaned” size=”12″></td>
</tr>
<tr>
<td align=”right”>Term :</td>
<td><input type=”text” id=”tLoan” size=”2″> years</td>
</tr>
<tr>
<td align=”right”>Interest rate :</td>
<td><input type=”text” id=”iLoan” size=”5″> % per annum</td>
</tr>
<tr>
<td colspan=”2″><hr></td>
</tr>
<tr>
<td align=”right”>Annuity :</td>
<td><input type=”text” id=”payLoan” size=”12″ readonly></td>
</tr>
<tr>
<td colspan=”2″><hr></td>
</tr>
<tr>
<td colspan=”2″><input type=”button” value=”Calculate” onClick=”calcATable();”></td>
</tr>
</table><br>
<div id=”amortTable”></div>
</body>
</html>
I tried to make it work on php. Here’s my php code:
[CODE]
<?php
$b=”<html>”;
$b.=”<script type=’text/JavaScript’>”;
$b.=” function calcATable()”;
$b.=” {“;
$b.=” aLoaned=document.getElementById(‘aLoaned’).value;”;
$b.=” i=document.getElementById(‘iLoan’).value/100;”;
$b.=” n=document.getElementById(‘tLoan’).value;”;
$b.=” annuity=(aLoaned*i)/(1-(1/Math.pow(1+i,n)));”;
$b.=” document.getElementById(‘payLoan’).value=parseInt(annuity*100)/100;”;
$b.=” nB ='<table border=’1′>’;”;
$b.=” nB+=’ <tr>’;”;
$b.=” nB+=’ <td>Year</td>’;”;
$b.=” nB+=’ <td>Interest</td>’;”;
$b.=” nB+=’ <td>Principal</td>’;”;
$b.=” nB+=’ <td>Balance</td>’;”;
$b.=” nB+=’ <tr>’;”;
$b.=” lBalance=aLoaned;”;
$b.=” sumInterest=0;”;
$b.=” sumPrincipal=0;”;
$b.=” for (y=1; y<=n; y++)”;
$b.=” {“;
$b.=” aInterest=lBalance*i;”;
$b.=” aPrincipal=annuity-aInterest;”;
$b.=” lBalance-=aPrincipal;”;
$b.=” sumInterest+=aInterest;”;
$b.=” sumPrincipal+=aPrincipal;”;
$b.=” nB+=’ <tr>’;”;
$b.=” nB+=’ <td>’+y+'</td>’;
$b.=” nB+=’ <td align=’right’>’+parseInt(aInterest*100)/100+'</td>’;”;
$b.=” nB+=’ <td align=’right’>’+parseInt(aPrincipal*100)/100+'</td>’;”;
$b.=” nB+=’ <td align=’right’>’+parseInt(lBalance*100)/100+'</td>’;”;
$b.=” nB+=’ </tr>’;”;
$b.=” }
$b.=” nB+=’ <tr>’;”;
$b.=” nB+=’ <td>Sum :</td>’;”;
$b.=” nB+=’ <td align=’right’>’+parseInt(sumInterest*100)/100+'</td>’;”;
$b.=” nB+=’ <td align=’right’>’+parseInt(sumPrincipal*100)/100+'</td>’;”;
$b.=” nB+=’ <td> </td>’;”;
$b.=” nB+=’ </tr>’;”;
$b.=” nB+='</table>’;”;
$b.=” document.getElementById(“amortTable”).innerHTML=nB;”;
$b.=” }”;
$b.=”</script>”;
$b.=”<body>”;
$b.=” <div align=’center’>”;
$b.=” <img src=’up.png’><br>”;
$b.=” <b>ABC Bank of Tacloban</b>”;
$b.=” </div><hr>”;
$b.=” <table>”;
$b.=” <caption>Loan Application Form<hr></caption>”;
$b.=” <tr>”;
$b.=” <td align=’right’>Name of borrower :</td>”;
$b.=” <td><input type=’text’ id=’nBorr’ size=’30’></td>”;
$b.=” </tr>”;
$b.=” <tr>”;
$b.=” <td align=’right’>Amount to be loaned :</td>”;
$b.=” <td><input type=’text’ id=”aLoaned” size=’12’></td>”;
$b.=” </tr>”;
$b.=” <tr>”;
$b.=” <td align=’right’>Term :</td>”;
$b.=” <td><input type=’text’ id=’tLoan’ size=’2′> years</td>”;
$b.=” </tr>”;
$b.=” <tr>”;
$b.=” <td align=’right’>Interest rate :</td>”;
$b.=” <td><input type=’text’ id=’iLoan’ size=’5′> % per annum</td>”;
$b.=” </tr>”;
$b.=” <tr>”;
$b.=” <td colspan=’2′><hr></td>”;
$b.=” </tr>”;
$b.=” <tr>”;
$b.=” <td align=’right’>Annuity :</td>”;
$b.=” <td><input type=’text’ id=’payLoan’ size=’12’ readonly></td>”;
$b.=” </tr>”;
$b.=” <tr>”;
$b.=” <td colspan=’2′><hr></td>”;
$b.=” </tr>”;
$b.=” <tr>”;
$b.=” <td colspan=’2′><input type=’button’ value=’Calculate’ onClick=’calcATable();’></td>”;
$b.=” </tr>”;
$b.=” </table><br>”;
$b.=” <div id=’amortTable’></div>”;
$b.=”</body>”;
$b.=”</html>”;
echo $b;
?>
When I try to open the file, it get a T_STRING error. Please help. What must be the problem with my codes? And can you please help me in revising the codes to make it work well in php?
Thank you in advance! ?