eva21 Posted January 29, 2009 Share Posted January 29, 2009 I have application1.php which does some calculations in javascript and displays it in html. I also have something that calls a bar graph and displays it using the following code: echo "<p><img src=\"php_bargraph.php?time=" . time() . "\"></p>"; The variables i need for this bargraph is calculated by an onblur event in javascript called doCalculations(). However, i have total1 and total2 as global variables in javascript... How can i pass total1 and total2 too php_bargraph.php and display the bar grpah with the right totals? Please help! Hmm...I was hoping to keep it in application1.php because the user has to be able to still see the tables and totals on the page. When the user sees the page, the bar grpah has zero values inside so there is no bar or anything. However, when the two javascript global variables have a value in it other than zero, i want it to update the bargraph on the spot and display it to the user. Link to comment https://forums.phpfreaks.com/topic/142964-passing-javascript-variable-total-to-php/ Share on other sites More sharing options...
ScotDiddle Posted January 29, 2009 Share Posted January 29, 2009 eva21, Take a look here... http://www.webmasterworld.com/forum88/2100.htm It explains how to use the JS new image() function to pass JS parms to PHP. Scot L. Diddle Link to comment https://forums.phpfreaks.com/topic/142964-passing-javascript-variable-total-to-php/#findComment-749584 Share on other sites More sharing options...
BioBob Posted January 29, 2009 Share Posted January 29, 2009 Two options for you. A: Create a Form. B: Create a Link. If youre going with A, you could set the variables generated by your scripts as hidden elements in the form. <form action="somepage.php" method="post"> <input type="hidden" name="var1"> <input type="submit" value="Submit"> If you want B: maybe try appending a link. <a href="somepage.php?var1=value1&var2=value2">Link</a> Then on your action page you submit or link to, use either $_POST['var1'] or $_GET['var1'] to get the data out and let php do its thing with it. Link to comment https://forums.phpfreaks.com/topic/142964-passing-javascript-variable-total-to-php/#findComment-749585 Share on other sites More sharing options...
eva21 Posted January 29, 2009 Author Share Posted January 29, 2009 Please explain more. Link to comment https://forums.phpfreaks.com/topic/142964-passing-javascript-variable-total-to-php/#findComment-749591 Share on other sites More sharing options...
rhodesa Posted January 29, 2009 Share Posted January 29, 2009 add an ID tag to your image: echo "<p><img id=\"graph\" src=\"php_bargraph.php?time=" . time() . "\"></p>"; add to your onBlur function: document.getElementById('graph').src = 'php_bargraph.php?total1=' + total1 + '&total2=' + total2; Link to comment https://forums.phpfreaks.com/topic/142964-passing-javascript-variable-total-to-php/#findComment-749602 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.