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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:52:06+00:00 2026-06-17T18:52:06+00:00

I have found a javascript function that gets the name of a country when

  • 0

I have found a javascript function that gets the name of a country when it is clicked on a map and a php snippet which gets the name of a country randomly from a file. What I want to do is to compare the result between these two so that I can tell if the user clcked on the map the right country according to the one appearing above in the question. I am not sure how to do it since they are not exactly simple variables and I tried to assign the php variable to a javascript one with no luck. Any guidance would be appreciated.

     ....  
        function getCountry(latLng) {
                geocoder.geocode( {'latLng': latLng},
                  function(results, status) {
                    if(status == google.maps.GeocoderStatus.OK) {
                      if(results[0]) {
                        for(var i = 0; i < results[0].address_components.length; i++) {
                          if(results[0].address_components[i].types[0] == "country") {
                            alert(results[0].address_components[i].long_name);
                          }
                        }
                      }
                      else {
                        alert("No results");
                      }
                    }
                    else {
                      alert("Status: " + status);
                    }
                  }
                );
              }


 ....

    Can you locate <?php
        $countries=file("countries.txt");
        $number_countries=count($countries);
        if($number_countries!==0){$number_countries.=-1;};
        $random=rand(0,$number_countries);
        $countryy=$countries[$random];
        echo "$countryy";
        ?>   on the map?
  • 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-17T18:52:08+00:00Added an answer on June 17, 2026 at 6:52 pm

    This is a bad practice, you should use ajax, but here is what you want.

    Can you locate <?php
        $countries=file("countries.txt");
        $number_countries=count($countries);
        if($number_countries!==0){$number_countries.=-1;};
        $random=rand(0,$number_countries);
        $countryy=$countries[$random];
        echo "$countryy";
        ?>   on the map?
        <script type="text/javascript">
           var country = <?php echo json_encode($countryy); ?>
    
          function getCountry(latLng) {
                  geocoder.geocode( {'latLng': latLng},
                    function(results, status) {
                      if(status == google.maps.GeocoderStatus.OK) {
                        if(results[0]) {
                          for(var i = 0; i < results[0].address_components.length; i++) {
                            if(results[0].address_components[i].types[0] == "country") {
                               if(results[0].address_components[i].long_name == country) {
                                  alert("right");
                               } else {
                                  alert("wrong");
                               }
                            }
                          }
                        }
                        else {
                          alert("No results");
                        }
                      }
                      else {
                        alert("Status: " + status);
                      }
                    }
                  );
          }
      </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Awhile back, I found the following javascript function that allows you to dynamically add
I have some code on a php page that gets an image filename strips
In this blog, http://www.bswebdev.com/2008/12/javascript-change-input-box-type-to-password/ I have found the following snippets for fixing change input
I have found Okapi Similarity measure can be used to calculated document similarity from
I have found that I have no problem using require to load something like
I have found many great answers to this from a year ago (when it
I have found this link: http://www.jfree.org/forum/viewtopic.php?f=3&t=6314 Its back in 2007 where they agree that
I have found that call stack helps in finding the line number of a
I have found that it is impossible to write ( file_put_contents or simple fwrite
I am using Googles Analytics api in Javascript. They provide a method that gets

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.