Jump to content

Recommended Posts

hi,

I'm new to php. I tried to get sum of two variables using java script. Value of one variable come from a php variable, Other one is a static value. here is the code

$price_per_day=100; it displays correctly. but when i try to add it with another variable it displays nothing. Please help me.

 

 

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>test</title>
    <script>
var total = 0;
var total_extra =<?php echo $price_per_day; ?>
var sum1=0;
 
function test(item){
if(item.checked){
total+= parseInt(item.value);
}else{
total-= parseInt(item.value);
}
//alert(total);
sum1=parseInt(total)+parseInt(total_extra);
document.getElementById('Totalcost').innerHTML = total + " /-";
document.getElementById('car_extra_total').innerHTML=sum1 ;
}
</script>
</head>
<body>
  <div class="checkbox">
<label>
 <input type="checkbox" name="channelcost" value="10" onClick="test(this);">Excess Protection<span class="right grey">10</span>
</label>
</div>
<div class="checkbox">
<label>
 <input type="checkbox" name="channelcost" value="50" onClick="test(this);">Additional Driver<span class="right grey">50</span>
</label>
</div>
<div class="checkbox">
<label>
 <input type="checkbox" name="channelcost" value="30"onClick="test(this);">GPS<span class="right grey">30</span>
</label>
</div>
<div class="checkbox">
<label>
 <input type="checkbox" name="channelcost" value="30" onClick="test(this);">Child Booster Seat  <span class="right grey">30</span>
</label>
</div>
<div class="checkbox">
<label>
 <input type="checkbox" name="channelcost" value="20" onClick="test(this);">Child Seat <span class="right grey">20</span>
</label>
</div>
<div class="checkbox">
<label>
 <input type="checkbox" name="channelcost" value="10" onClick="test(this);">Baby Seat <span class="right grey">10</span>
</label>
</div>
  
  <div class="padding20">
<table class="wh100percent size12 bold dark">
 
<tr>
<td>Extras total</td>
<td class="textright">$<span id="Totalcost"> </span></td>
</tr>
</table>
<div class="fdash mt10"></div><br/>
<span class="size14 dark bold">Total price:</span>
<span class="size24 green bold right margtop-5">$<span id="car_extra_total"></span></span>
</div>
 
</body>
</html>
 
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.