Mga sir pa help naman po super newbie lang sa programming ano po kayang mali dito PHP po sya nasa baba po ng php code yung JavaScript version nya
instruction po kasi is kelangan iconvert ko sya from Javascript to php....pasensya na po hindi ko lang talaga mapagana sya........
Eto po yung JavaScript Version nya......
instruction po kasi is kelangan iconvert ko sya from Javascript to php....pasensya na po hindi ko lang talaga mapagana sya........
PHP:
<!DOCTYPE html>
<html>
<head>
<title>Money</title>
</head>
<body>
<form method="POST" action="">
<input type="text" name="number">
<button type="submit" name="btnSubmit">Submit</button>
</form>
<?php
if(isset($_POST['btnSubmit']))
{
$currency = array("1000", "500", "100", "50", "20", "10", "5", "1");
$currency = $_POST['currency'];
$number = $_POST['number'];
$money = array();
for ($i=0; $i <8 ; $i++)
{
$currValue = $_POST['$currValue'];
$_POST['currValue'] = ($_POST['number'] - $_POST['number'] % $_POST['currency'][$i])/$_POST['currency'][$i]);
array_push($currValue, $money);
$number = $_POST['number'] - ($_POST['currency'][$i] * $_POST['currValue']);
}
for ($i=0; $i <8 ; $i++)
{
$label = $_POST['label']
$_POST['label'] = $currency[$i] < 20 ? "Coins" : "Bill";
echo ($currency[$i]." ".$_POST['label']."=".$money[$i]."<br><br>");
}
}
?>
</body>
</html>
Eto po yung JavaScript Version nya......
JavaScript:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input type="text" id="number">
<input type="button" onclick="test()" id="BtnTest" value="Try Me">
</body>
<script type="text/javascript">
function test()
{
var curr = ["1000","500","100","50","20", "10", "5", "1"];
var number=document.getElementById("number").value;
var ctrcurr= [];
for (var i=0; i < 8; i++) {
var currValue = (parseInt(number) - parseInt(number) % parseInt(curr[i]) )/ parseInt(curr[i]) ;
ctrcurr.push(currValue);
number = number - ( curr[i] * currValue) ;
}
for (var i=0; i < 8; i++) {
var label = curr[i] < 20 ? "Coins" : "Bill";
document.write(curr[i]+" "+ label + " = "+ ctrcurr[i]+ "<br><br>");
}
}
</script>
</html>