I know this is a somewhat strange request and is probably not feasable, but I thought I would ask anyway :)

I have a form, and on the final page of the form it displays all of the results of the user's entries. The problem is some of these results are calculated by a complicated javascript function that then displays the proper result. For example, the javascript takes a number for the arrival location specified on the form and then finds that number to mean "Atlanta". Javascript then places the right value in a table via the "innerhtml" dom property.

When the user clicks "Submit" on the final page an e-mail is sent to the user via php script. Is there anyway to capture the javascript output for use in a php variable.

Basically I want to capture the innerhtml value javascript places and use this value in my PHP script. I am trying to avoid re-writing the javascript calculations in PHP and was looking for a way to pass this information from the javascript function to the php script. Any ideas?

While I myself don't know how to do this, I can say this, with enough time and resources anything can be done with php.

Add hidden fields to the form with the Submit button, the values can then be retreived using $_POST or $_GET in PHP.

xan is right and the code for it is something like the below. First in your form add the following code:

<input type="hidden" value="" name="js" id="js">

Then to update its value in the javascript function use the following javascript:

<script>
document.getElementById("js").innerHTML="new value";
//or
document.getElementById("js").value="new value";
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.