Title: pass a variable to jquery function and get returned value in php
Last modified: August 20, 2016

---

# pass a variable to jquery function and get returned value in php

 *  [jusmudy](https://wordpress.org/support/users/jusmudy/)
 * (@jusmudy)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/pass-a-variable-to-jquery-function-and-get-returned-value-in-php/)
 * Actually I have defined a jquery function this
 * _[ Moderator Note: Please post code or markup snippets between backticks or use
   the code button. ]_
 *     ```
       <script language="JavaScript" type="text/javascript">
       jQuery(document).ready(function convertcurrency($){
   
       var temp;
       								temp=$('#hotel-description table>tbody>tr>.test').html();
       console.log(temp);
       return temp;
       									 });
       </script>
   
       Now I am calling the same function in php like this
       <?php
       $t="some value"
       $temp2=convertcurrency($t);
       echo $temp2;?>
       ```
   
 * I have kept the $ sign in jquery function otherwise its showing error
    $(“#hotel-
   description table>tbody>tr>.test”) is null
 * when I am keeping the $ sign there the console displaya the value of temp accurately.
 * Please help the replier will be greatly appericiated.
    thanks

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/pass-a-variable-to-jquery-function-and-get-returned-value-in-php/#post-2957382)
 * You can’t call a jQuery function with PHP. They are two completely different 
   languages and run at different times. PHP runs on the server before the web page
   is sent to the browser. jQuery (being Javascript) runs in the web browser on 
   the client machine and not on the server at all.
 *  Thread Starter [jusmudy](https://wordpress.org/support/users/jusmudy/)
 * (@jusmudy)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/pass-a-variable-to-jquery-function-and-get-returned-value-in-php/#post-2957392)
 * Thanks for showing interest.
    Is there any way to access jquery variable in php
   without using cookies.
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/pass-a-variable-to-jquery-function-and-get-returned-value-in-php/#post-2957394)
 * No. PHP has already stopped running on the server by the time that jQuery starts
   running on somebody’s computer in a house or office. If jQuery does something,
   PHP has no way to know. PHP would have to be able to reach into the future and
   jump across space to get a jQuery value.
 * What you have to do is pass things back to PHP from jQuery after the page has
   loaded and the Javascript has ran. In other words and in this order, 1)PHP runs,
   2)sends the page to the browser, 3)jQuery runs, 4)sets your variable, 5)jQuery
   send the variable back to the server and thus to PHP.
 * You can pass things back with jQuery.get, jQuery.post, or by setting cookies.
   You can also use Javascript to set form fields which will be sent back to the
   server, and hence to PHP, when the form is submitted. You can also alter URLs
   to include GET parameters. The cookies, the form, and GET string solutions will
   only take effect on the next page load. With jQuery.get and jQuery.post you can
   use Javascript to dynamically rewrite the page– basically, AJAX.
 *  Thread Starter [jusmudy](https://wordpress.org/support/users/jusmudy/)
 * (@jusmudy)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/pass-a-variable-to-jquery-function-and-get-returned-value-in-php/#post-2957395)
 * thanks i sort a bit of problem….now i only want to pass an array from jquery 
   into php, using cookie is that possible but i dont want to use cookie…plz help
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/pass-a-variable-to-jquery-function-and-get-returned-value-in-php/#post-2957405)
 * Those are your options, as far as I know. I explained why. There may be variations
   on those, but that is about it. Pick one of those options and make it work.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘pass a variable to jquery function and get returned value in php’ is 
closed to new replies.

## Tags

 * [jquery error](https://wordpress.org/support/topic-tag/jquery-error/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/pass-a-variable-to-jquery-function-and-get-returned-value-in-php/#post-2957405)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
