I need the code below written in PHP. var Cost, GST, PST, Grand_Total; function
ID: 3768108 • Letter: I
Question
I need the code below written in PHP.
var Cost, GST, PST, Grand_Total;
function createTable()
{
var divPage = document.getElementById('divPage');
var mytable = document.createElement("table");
var mytablebody = document.createElement("tbody");
for (var intRow = 0; intRow < 3; intRow++)
{
var mycurrent_row=document.createElement("tr");
for(var intCol = 0; intCol < 3; intCol++)
{
var mycurrent_cell = document.createElement("td");
var chkbox = document.createElement('input');
chkbox.setAttribute("type", "checkbox");
mycurrent_cell.appendChild(chkbox);
mycurrent_row.appendChild(mycurrent_cell);
}
mytablebody.appendChild(mycurrent_row);
}
mytable.appendChild(mytablebody);
divPage.innerHTML = mytable.outerHTML;
}
function tally()
{
Cost = 0;
if (document.orderform.Book.checked) { Cost = Cost + 12.99; }
if (document.orderform.Calendar.checked) { Cost = Cost + 15.99; }
if (document.orderform.Shirt.checked) { Cost = Cost + 15.99; }
if (document.orderform.Mousepad.checked) { Cost = Cost + 6.99; }
if (document.orderform.Mug.checked) { Cost = Cost + 9.99; }
if (document.orderform.Poster.checked) { Cost = Cost + 10.00; }
if (document.orderform.Decal.checked) { Cost = Cost + 5.00; }
if (document.orderform.Clock.checked) { Cost = Cost + 26.00; }
if (document.orderform.Hat.checked) { Cost = Cost + 25.00; }
GST = (Cost * 0.07);
PST = (Cost * 0.07);
Cost = dollar(Cost);
GST = dollar(GST);
PST = dollar(PST);
Grand_Total = parseFloat(Cost) + parseFloat(GST) + parseFloat(PST);
Grand_Total = dollar(Grand_Total);
document.orderform.Total.value = "$" + Cost;
document.orderform.GST.value = "$" + GST;
document.orderform.PST.value = "$" + PST;
document.orderform.GrandTotal.value = "$" + Grand_Total;
}
function dollar (amount)
{
amount = parseInt(amount * 100);
amount = parseFloat(amount/100);
if (((amount) == Math.floor(amount)) && ((amount - Math.floor (amount)) == 0))
{
amount = amount + ".00"
return amount;
}
if ( ((amount * 10) - Math.floor(amount * 10)) == 0)
{
amount = amount + "0";
return amount;
}
if ( ((amount * 100) - Math.floor(amount * 100)) == 0)
{
amount = amount;
return amount;
}
return amount;
}
Explanation / Answer
$Cost, $GST, $PST, $Grand_Total;
function createTable()
{
$divPage = document.getElementById('divPage');
$mytable = document.createElement("table");
$mytablebody = document.createElement("tbody");
for ( $intRow = 0; $intRow < 3; $intRow++)
{
$mycurrent_row=document.createElement("tr");
for( $intCol = 0; $intCol < 3; $intCol++)
{
$mycurrent_cell = document.createElement("td");
$chkbox = document.createElement('input');
chkbox.setAttribute("type", "checkbox");
$mycurrent_cell.appendChild(chkbox);
$mycurrent_row.appendChild($mycurrent_cell);
}
$mytablebody.appendChild($mycurrent_row);
}
$mytable.appendChild($mytablebody);
divPage.innerHTML = $mytable.outerHTML;
}
function tally()
{
$Cost = 0;
if (document.orderform.Book.checked) { $Cost = $Cost + 12.99; }
if (document.orderform.Calendar.checked) { $Cost = $Cost + 15.99; }
if (document.orderform.Shirt.checked) { $Cost = $Cost + 15.99; }
if (document.orderform.Mousepad.checked) { $Cost = $Cost + 6.99; }
if (document.orderform.Mug.checked) { $Cost = $Cost + 9.99; }
if (document.orderform.Poster.checked) { $Cost = $Cost + 10.00; }
if (document.orderform.Decal.checked) { $Cost = $Cost + 5.00; }
if (document.orderform.Clock.checked) { $Cost = $Cost + 26.00; }
if (document.orderform.Hat.checked) { $Cost = $Cost + 25.00; }
$GST = ($Cost * 0.07);
$PST = ($Cost * 0.07);
$Cost = dollar($Cost);
$GST = dollar($GST);
$PST = dollar($PST);
$Grand_Total = parseFloat($Cost) + parseFloat($GST) + parseFloat($PST);
$Grand_Total = dollar($Grand_Total);
document.orderform.Total.value = "$" + $Cost;
document.orderform.$GST.value = "$" + $GST;
document.orderform.$PST.value = "$" + $PST;
document.orderform.GrandTotal.value = "$" + $Grand_Total;
}
function dollar ($amount)
{
$amount = parseInt($amount * 100);
$amount = parseFloat($amount/100);
if ((($amount) == Math.floor($amount)) && (($amount - Math.floor ($amount)) == 0))
{
$amount = $amount + ".00"
return $amount;
}
if ( (($amount * 10) - Math.floor($amount * 10)) == 0)
{
$amount = $amount + "0";
return $amount;
}
if ( (($amount * 100) - Math.floor($amount * 100)) == 0)
{
$amount = $amount;
return $amount;
}
return $amount;
}