1

I have this html code:

<!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>Untitled Document</title>
</head>

<body>
     <form action="test.php" method="get">
        <input type="text" placeholder="City" id="city" />
        <br />
        <input type="text" placeholder="Region" id="region" />
     </form>
     <div id="result"></div>
</body>
</html>

And this is my php code:

<?php
     $city = $_GET['city'];
     $region = $_GET['region'];
     $result = "You entered " . $city . " and " . $region;
?>

And I want to get the $result from the php file immediately and show it in the div with id result.

Ikari
  • 3,176
  • 3
  • 29
  • 34

1 Answers1

-1

As it turns out from your comments, you need to know how to do AJAX. Use jQuery and some hints on the jS part :

$('#region').mouseout(function() {
 $('#result').fadeOut();
 $.ajax({
  url: window.location.href+"api/user/"+$(this).val(),
  dataType: "html"
 }).done(function(data) {
  $('#result').fadeIn();
  $('#result').text(data);
 });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
bluefog
  • 1,894
  • 24
  • 28