• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

213
Views
how to get javascript variable value in php variable

I am working on an app where I need to get the location of the user on the login page my app is working a little bit fine but I am stuck on it when i get the location of user that lang and long i want to store in any PHP variable so I can insert that values in DB by PHP

here is my code:

<html> 
<head>
<script>
var x = document.getElementById("demo");
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  x.innerHTML = "Latitude: " + position.coords.latitude +
  "<br>Longitude: " + position.coords.longitude;
  
}
</script>

</head> 

<body> 
    <?php 
        echo $variable = "<script>document.write(x.innerHTML)</script>";
    ?>
</body> 

please guide me, my friends...

Thanks

about 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error