I have a simple code with a javascript checkbox. You can see the frontend in this website:
englishforyou.ir
When you check the check box the total price should show the new figure but it doesn't.
All my code is in one page:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div>
<div>
<?php
$title= "pen" ;
$penprice= 7 ;
?>
<form id="formpayment" action="<?php echo $urlname?>" method="post" >
<p style="color:blue; font:11px">
<input type="checkbox" id="check" name="kol" />Please add the eraser (Add 5$)
<br>
</p>
<table border="0" >
<tr>
<td><?php echo $title; ?>
</td>
<td ><input style="width: 60px; padding: 2px; border: 0px " class="txt" type="text" name="priceofpen" id="priceofpen" value="<?php echo $penprice ;?>
" readonly/> $
</td>
<td>
</td>
</TR>
<tr>
<td><?php echo "Eraser price"; ?>
</td>
<td > <input style="width: 50px; padding: 2px; border: 0px " name="priceoferaser" class="txt" id="priceoferaser" value="0" readonly="readonly" /> $
</td>
<td>
</td>
</TR>
<tr>
<td colspan="3"> <hr />
</td>
</TR>
<tr id="summation">
<td> Total:
</td>
<td>
<input style="width: 60px; padding: 2px; border: 0px " type=number name="total" id="total" value="<?php echo $penprice;?>" readonly="readonly">$
</td>
<td>
</td>
</TR>
</table>
</p><br />
</form>
</div>
</div>
<script>
$('#check').on('change',function(){
var eraserprice = "5"
var c=parseFloat(eraserprice)+ parseFloat(<?php echo $penprice;?>);
if(this.checked)
$('#total').val( c )&& $('#priceoferaser').val( parseFloat(5000) ) )
else
$('#total').val( <?php echo $penprice;?>)&& $('#priceoferaser').val( parseFloat(0) )
})
</script>
</div>
</body>
</html>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire