Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9111083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:25:21+00:00 2026-06-17T03:25:21+00:00

I have some PHP code inside the script so I need the JavaScript value

  • 0

I have some PHP code inside the script so I need
the JavaScript value as a PHP variable, as follows:

<script>
;
 var js_var = 123;
 var php_var = <?php js_var ?>;
 alert(php_var);
;
</script>

Using jQuery to send the value to a PHP page will return the value but not as a PHP variable:

$.get("page.php", {js_var_name: js_var}, function(data) {alert(data)});

I tried also all jQuery AJAX functions: load(), post() and the ajax() method, none of them pass back the value of PHP as above requested.

Is it possible to implement the above with jQuery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:25:22+00:00Added an answer on June 17, 2026 at 3:25 am

    Likely you have a syntax issue with :

    var php_var = <?php js_var ?>;
    

    Unless you used define() your php variable should start with $ and you need to echo it so that it gets printed to the page

    var php_var = <?php echo $js_var ?>;
    

    If you are assuming that php will read the prior javascript js_var=123 it won’t. Javscript is a client side language and php is server side.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to have some php code inside javascript <script ...> <?php echo ...
I need to write some PHP code inside a Javascript's document.write() . This is
I have some code like this inside a file script.php : class ABC {
I have a chunk of HTML code (with some PHP vars echoed inside of
Suppose I have some PHP code running inside a web server, for example, running
I made this PHP chatbox which supports some JavaScript code. I have these 'images'
I have the following code where I declare a PHP array variable and inside
I have some JavaScript, which is generated by PHP code, using a template. The
I have some PHP code that generates dynamic tables of data on the fly.
I have some PHP code that is designed to make a spreadsheet with formulas

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.