Jump to content

Passing Javascript variable total to php?


eva21

Recommended Posts

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.

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

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.

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;

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.