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 8241797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:57:01+00:00 2026-06-07T20:57:01+00:00

I want to insert javascript value into the php session variable but inside the

  • 0

I want to insert javascript value into the php session variable but inside the javascript function.

Here is what I have tried and it is not working:

function languageChange()
{
 var lang = $('#websites1 option:selected').val();
 <?php $_SESSION['SESS_LANGUAGE']?> = lang;
 alert(<?php echo $_SESSION['SESS_LANGUAGE']?>);
}
  • 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-07T20:57:02+00:00Added an answer on June 7, 2026 at 8:57 pm

    You cannot access it directly (the way you are doing). However, it can be done using AJAX.
    Here is the perfectly working solution.

    Here is the HTML:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>1</title>
    </head>
    
    <body>
    <form id="form1" name="form1" method="post" action="">
        <label for="websites1">Websites</label>
        <select name="websites1" id="websites1">
            <option value="Design">Design</option>
            <option value="Dev">Dev</option>
            <option value="Ecom">Ecom</option>
        </select>
    </form>
    <script type="text/javascript" src="js/jquery_1.7.1_min.js"></script> 
    <script type="text/javascript">
    
    $(document).ready(function() {
    
        function languageChange()
        {
             var lang = $('#websites1 option:selected').val();
    
            return lang;
        }
    
    
        $('#websites1').change(function(e) {                    
    
            var lang = languageChange();
    
            var dataString = 'lang=' + lang;
    
            $.ajax({
    
                type: "POST",
                url: "pass_value.php",
                data: dataString,
                dataType: 'json',
                cache: false,
                success: function(response) {
    
                        alert(response.message);
    
                    }
            });
    
            return false;
    
        });
    
    });
    
    </script>
    </body>
    </html>
    

    Here is the AJAX part:

    //pass_value.php
    
    <?php session_start();
    
    $_SESSION['SESS_LANGUAGE'] = $_POST['lang'];
    
    $_SESSION['SESS_LANGUAGE'] = 'This is my PHP session var --->'.$_SESSION['SESS_LANGUAGE'];
    
    print json_encode(array('message' => $_SESSION['SESS_LANGUAGE']));
    die();
    
    
    ?>
    

    EDIT 1:

    Once you run the code, simply select any of the other options from the dropdown menu and you will receive an alert that gives you the value of the php session variable along with the custom text that I added to it.

    EDIT 2:

    If you want to run my solution on your end, make sure you point to core jQuery js file correctly. My jquery code points to src="js/jquery_1.7.1_min.js". Make sure you update this.

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

Sidebar

Related Questions

I want to insert the following include tag into my webpage using JavaScript. <!--#include
I would like to insert a parameter value found the url into my javascript
I want to save my canvas into MySQL database (BLOB cell). I have function
I want insert a custom snippet into an XML file from code within an
I want to insert a record into a MySQL database table from a formulaire.
I want to insert a date record to an Access database. Here is my
I want to insert widgets into my ItemsControl and make them resizeable. How do
i want to insert all processes that running into listbox, and also how to
I want to insert an Image inside my Polygon , possibly at the center
I'm writing some javascript (a greasemonkey/userscript) that will insert some input fields into a

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.