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

  • SEARCH
  • Home
  • 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 6838861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:38:53+00:00 2026-05-26T23:38:53+00:00

First I thought that I had to convert JavaScript to PHP, but then I

  • 0

First I thought that I had to convert JavaScript to PHP, but then I found out that I cannot because of server and client side executions. So now I simply want to send ONE variable

<script type="text/javascript">
function scriptvariable()
{        
    var theContents = "the variable";
}
</script>

to a PHP variable

<?php
$phpvariable
?>

That function in the JavaScript executes when let’s say I click on a button.

Now I have no idea on how to assign that phpvariable to the JavaScript one to use the phpvariable to look up stuff in my database. I know I can add it to my url or some thing and refresh the page, but I would like to do it with AJAX as I might have to use this Ajax method further in my webpage.

So is there an easy way to do this without having to dump pages of code on my page to do one simple thing?

  • 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-05-26T23:38:54+00:00Added an answer on May 26, 2026 at 11:38 pm

    As Jordan already said you have to post back the javascript variable to your server before the server can handle the value. To do this you can either program a javascript function that submits a form – or you can use ajax / jquery. jQuery.post

    Maybe the most easiest approach for you is something like this

    function myJavascriptFunction() { 
      var javascriptVariable = "John";
      window.location.href = "myphpfile.php?name=" + javascriptVariable; 
    }
    

    On your myphpfile.php you can use $_GET['name'] after your javascript was executed.

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

Sidebar

Related Questions

In our project we are using CentOS5.6+php5.2.17+libmemcached+php memcached2+moxi+membase First time i thought that it
Okay at first I thought this would be pretty straightforward. But I can't think
here's the main code at first I thought is was the message box but
does the following integer arithmetic property hold? (m/n)/l == m/(n*l) At first I thought
Ok first of all, the unicorn avatars are hilarious. Seriously, I thought my account
I very rarely meet any other programmers! My thought when I first saw the
I'm using $lang=$_SERVER['HTTP_ACCEPT_LANGUAGE']; to detect the language of the browser. At first, I thought
My first thoughts are Erlang, or Java, but I wanted to know from others
And I'm not meaning Bits Per Minute, but Business Process Management. At first though
What is the reason null doesn't evaluate to false in conditionals? I first thought

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.