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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:48:38+00:00 2026-06-09T15:48:38+00:00

Here’s what I am trying to do. I have the following script which will

  • 0

Here’s what I am trying to do.

I have the following script which will POST data from index.php on the same page(index.php):

<script type="text/javascript">

function loadabc(){
            var optionValue = jQuery("select[name='citycountrystores']").val();     
                    jQuery.ajax({
                        type: "POST",
                        url: "index.php",
                        data: ({result: optionValue}),
                        success: function(response){
                            jQuery("#cityAjax").html(response);
                            jQuery("#cityAjax").show();
                        }
                    });

I want to access the POST data in php.
The php statements are written in the same javascript.
I need to access $_POST[‘result’] in a php if statement like:

<?php
if($check==$_POST['result'])
{
code....
.........
    }
    ?>
}//Function loadabc end
    </script>

This is my select box

<select id="citycountrystores" name="citycountrystores" onchange="loadabc();">
  <option value="76">City1</option>
  <option value="77">City2</option>
  <option value="78">City3</option>
</select>

I can see the POST value(76 or 77 or 78) in the console. But i would like to know how to store it in a php variable for immediate access.

Can someone please tell me how I can do this, or any other approach to achieve this.

  • 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-09T15:48:40+00:00Added an answer on June 9, 2026 at 3:48 pm

    If you want to access same page from AJAX you need to end your script before it prints the rest of the page out, first lines in code should be:

    <?php
        if(isset($_POST['result']) &&  ($_POST['result'] != '')){
                if($_POST['result'] == 77){
                    echo "My selected code: ".$_POST['result'];
                } else {
                    echo "something else";
                }
                die();
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is what I am trying to achieve in PHP: I have this string:
Here is what I am currently doing. PHP echo's out the recent post in
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here is my problem : I have a post controller with the action create.
Here is the problem that I am trying to solve. I have two folders
Here is my code (Say we have a single button on the page that
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
Here I am trying to retrieve the response from the server and display it,

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.