• 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)
  • 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

    (@jusmudy)

    Thanks for showing interest.
    Is there any way to access jquery variable in php without using cookies.

    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

    (@jusmudy)

    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

    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.