nathan666 wrote:
I have a jQuery function that receives a value from a PHP function
It is pretty difficult to answer a question which starts from the wrong idea expressed in the sentence shown above. This is not what really happens.
PHP works on the server side only, jQuery — on the client side only. PHP generates a whole HTML page and the server sends it to the client side in HTTP response to client's previous request. The client side loads the page; and the browser tries to run the scripts, including your jQuery script. In most cases, you need to handle "document ready" event using
$(document).ready(function() { /*...*/ }
in your jQuery script. Now, your script never receive any values from any PHP functions; instead, the result of PHP execution is the generation of the whole HTML page including your scripts. Even though some part of this text is parametric, for a script this is nothing but an embedded static text.
If you need to send a "POST", "GET" or any other HTTP request from the jQuery, you can use jQuery Ajax methods like
jQuery.post()
,
jQuery.get()
, etc., see
http://api.jquery.com/category/ajax/[
^].
When a request is sent via Ajax, the process is repeated from scratch. The only result of the previous calculations which is preserved is the content of the request. If you need anything else, you need to use PHP
session management, see
http://php.net/manual/en/ref.session.php[
^].
I think if you put these considerations all together, you will explain the problem correctly
to yourself and will see how to solve it.
—SA