abbos Posted August 17, 2008 Share Posted August 17, 2008 I get the feeling i've been going round in circles with this now and am hoping someone can help and show me where i'm going wrong. I have the following code on a single page: echo "<script language=\"javascript\">\n"; echo "function showlabour();\n"; echo "var tot = <?php echo $total=$totallinecost+$totallabourcost+$delivery ?>"; echo "</script>"; echo "<script language=javascript>\n"; echo "document.write(tot)\n"; echo "</script>\n"; // displays grey line at bottom echo '<tr><td width="90%" colspan="3"><hr size="1"></td></tr>'; echo "</tr>"; echo "</table>"; //<a href=\"$_SERVER[php_SELF]?action=empty\" onclick=\"return confirm('Are you sure?');\">Empty</a> // show empty cart link which links to this page, but with an action of empty. A simple bit of javascript in the onlick echo "<table border=\"0\" align=\"center\" width=\"90%\">"; echo "<tr>"; echo "<td colspan=\"3\" align=\"right\"><input name='submit' type='submit' value='update' /></td>"; echo "<td colspan=\"2\" align=\"right\"><input type='checkbox' onclick='showlabour();' />labour</td>"; echo "</tr>"; echo "</table>";echo "<table border=\"0\" align=\"center\">"; echo "<tr>"; echo "<td colspan=\"3\" align=\"center\"><a href=\"quote_summary.php\">Download Summary</a></td>"; echo "<td colspan=\"3\" align=\"center\"><a href=\"quote_summary.php?title=$title&quantity=$quantity&line_cost=$line_cost&delivery=$delivery&labour=$labour&total=$total\">Print Summary</a></td>"; echo "</tr>"; echo "</table></form>"; My issue is that I have a php variable called $total. When the above page loads that value is set to 10 for example. I am trying to put a tickbox on the page so that when clicked it recalculates the value of $total and then displays that new value. Can anyone help me? Thanks is advance, Link to comment https://forums.phpfreaks.com/topic/120053-help-with-tick-box-please/ Share on other sites More sharing options...
MasterACE14 Posted August 17, 2008 Share Posted August 17, 2008 echo'ing within a echo with PHP tags isn't going to work, and you haven't closed the echo. <?php echo $total=$totallinecost+$totallabourcost+$delivery; // << missing the semi colon ?> and it would be easier if you were using the Heredoc syntax. example: <?php echo = <<<_JAVASCRIPT <script language="javascript"> alert("Test Alert"); </script> _JAVASCRIPT; ?> Link to comment https://forums.phpfreaks.com/topic/120053-help-with-tick-box-please/#findComment-618473 Share on other sites More sharing options...
Barand Posted August 17, 2008 Share Posted August 17, 2008 PHP runs on the server then sends the page to the client. Javascript runs on the client. You can't, therefore, execute PHP code directly from js as the PHP processor has completed. Either do it all in javascript or use xmlhttp request to call a PHP script (AJAX) Link to comment https://forums.phpfreaks.com/topic/120053-help-with-tick-box-please/#findComment-618483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.