sir i have got a problem with my project i calculated the sum of certain things in PHP variable say $sum
, now i want to show its value in a dialogue box like sum of that particular things=that calculated sum using java script how will i do that?here is what i wrote,its not working what will i do?where sum1 is the variable value i want to print in the JavaScript dialogue box and size13 to size24 i calculated using some sql query .
index.php
<?php>
$sum1=$size13+$size14+$size15+$size16+$size17+$size18+$size19+$size20+$size21+$size22+$size23+$size24;
echo '<script type="text/javascript">
alert("Total Traffic-violation Solved During the year -2014-");
echo $sum1;
window.location=\'index.php\';</script>';
<?>
Change the alert to:
alert("Total Traffic-violation Solved During the year -2014-'.$sum1.'");
Concatenate the sum into the string.
Also, you begin with <?php and end with ?>, not <?php> and <?> - or are you using a very very weird php parser?
You should use next line
alert("Total Traffic-violation Solved During the year -2014-'.$sum1.'");
Try this, use $sum1
variable inside js alert() function;
<?php>
$sum1=$size13+$size14+$size15+$size16+$size17+$size18+$size19+$size20+$size21+$size22+$size23+$size24;
echo '<script type="text/javascript">
alert("Total Traffic-violation Solved During the year -2014- '.$sum1.'");
window.location=\'index.php\';
</script>';
?>
OR
<script type="text/javascript">
alert("Total Traffic-violation Solved During the year -2014- <?php echo $sum1; ?>");
window.location=\'index.php\';
</script>
This will work:
<?php
$sum1 = 50;
echo '<script type="text/javascript">
alert("Total Traffic-violation Solved During the year -2014-: '.$sum1.'");
window.location=\'index.php\';
</script>';
?>
Just changed your sums etc...