title: Load Google Maps on webpage using Javascript and PHP through drop down form
body: <p>I am having two drop down lists on a html page. The data is coming from a mysql database and contains information like latitude, longitude and address. The user selects one item from the drop down and clicks on submit.</p>
  
  <p>At this stage, I want to display a google map and put a marker at the latitude and longitude. Then, when the user selects the option from second drop down, I want to just add a marker on that map.</p>
  
  <p>Currently, I am able to load the map once he clicks the submit from first drop down but all the options I tried to drop the pins are not working.</p>
  
  <p>Here is the code I have achieved till now:</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
  require_once('auth.php');
  include ('LoginConfig.php');
  include ('FetchAgentDetails.php');
  include ('FetchDeliveryDetails.php');
  ?&gt;
  
  
  
  &lt;!--
  To change this template, choose Tools | Templates
  and open the template in the editor.
  --&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;
  
          &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
          &lt;title&gt;Delivery Management System&lt;/title&gt;
          &lt;script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA0Rm5aK0BYu1f_TzhjkG97cchHHlQfrQY&amp;sensor=false"&gt;
  &lt;/script&gt;
  &lt;style type="text/css"&gt;
  html {height:100%}
  body {height:100%;margin:0;padding:0}
  #googleMap {height:100%}
  &lt;/style&gt;
  &lt;script&gt;
  function initialize()
  {
  var mapProp = {
    center:new google.maps.LatLng(51.508742,-0.120850),
    zoom:5,
    mapTypeId:google.maps.MapTypeId.ROADMAP
    };
  var map=new google.maps.Map(document.getElementById("googleMap")
    ,mapProp);
  }
  google.maps.event.addDomListener(window, 'load', initialize);
  &lt;/script&gt;
  &lt;/head&gt;
  
          &lt;style type="text/css"&gt;
              &lt;!--
              .style1 {
                  font-size: 20px;
                  font-weight: bold;
              }
  
              --&gt;
          &lt;/style&gt;
          &lt;style type="text/css"&gt;
              table.collection {width:250px;border:2px solid black;border-style: outset;border-collapse:collapse;}
              table.collection tr {background-color:#fff; border-bottom: 1px #99b solid;padding:10px;}
              table.collection tr:hover {background-color:#ffe;}
              table.collection td {display:table-cell;border-bottom: 1px #99b solid; padding:10px;}
              table.collection td a {text-decoration:none; display:table-row; padding:0px; height:100%;}
          &lt;/style&gt;
  
      &lt;/head&gt;
  
      &lt;body bgcolor="#8E8E38"
          &lt;div style="clear: right;"&gt;
              &lt;p align="left" class="style1"&gt;Welcome Delivery Manager! &lt;/p&gt;
              &lt;img style="position: absolute; top: 0; right: 0;" src="./Images/logo.jpg" alt="Company Logo" width="90" height="60" align="middle"&gt;&lt;/img&gt;
          &lt;/div&gt;
          &lt;p align="left"&gt;&lt;a href ="Home.php"&gt;Home&lt;/a&gt;&lt;/p&gt;
          &lt;hr&gt;&lt;/hr&gt;    
  
  
          &lt;!-- START Main Wrap --&gt;
          &lt;form method="post"&gt;
              &lt;fieldset&gt;
                  &lt;div style="clear: left;float:left;"&gt;
                      &lt;label for="deliveryList"&gt;Delivery Items:&lt;/label&gt;
                      &lt;select name="deliveryList" id="deliveryList"&gt;
                          &lt;option value="Select delivery item" selected="selected"&gt;Select delivery item&lt;/option&gt;
  &lt;?php
  $deliveryHandler = new FetchDeliveryDetails();
  $itemNameArray = $deliveryHandler-&gt;getItemNames();
  
  foreach ($itemNameArray as $innerArray) {
      if (is_array($innerArray)) {
          $value = $innerArray['itemName'];
          echo "&lt;option value=\"$value\"";
          if (isset($_POST['deliveryList']) &amp;&amp; $_POST['deliveryList'] == $value)
              echo 'selected';
          echo "&gt;" . $value . "&lt;/option&gt;\n";
      }
  }
  ?&gt;
                      &lt;/select&gt;
                      &lt;input type="submit" name="submit" id="submit"  value="Submit"/&gt;
                  &lt;/div&gt;
  
                  &lt;div style="clear: right;float:right;"&gt;
                      &lt;label for="agentList"&gt;Avaliable Agent:&lt;/label&gt;
                      &lt;select name="agentList" id="agentList"&gt;
                          &lt;option value="" selected="selected"&gt;Select agent to assign&lt;/option&gt;
  &lt;?php
  $agentHandler = new FetchAgentDetails();
  $agentNameArray = $agentHandler-&gt;getAgentNames();
  foreach ($agentNameArray as $innerArray) {
      if (is_array($innerArray)) {
  
          $agentId = $innerArray['agentId'];
          $firstNameValue = $innerArray['firstname'];
          $lastNameValue = $innerArray['lastname'];
          $fullName = $firstNameValue . ' ' . $lastNameValue;
          echo "&lt;option value=\"$agentId\"&gt;$fullName&lt;/option&gt;\n";
      }
  }
  ?&gt;
                      &lt;/select&gt;
                      &lt;input type="submit" name="agentSubmit" id="agentSubmit"  value="Check Location"/&gt;
                  &lt;/div&gt;
              &lt;/fieldset&gt;
          &lt;/form&gt;
  &lt;?php
  if (isset($_POST['deliveryList'])) {
      $selectedItemName = $_POST['deliveryList'];
      $deliveryHander = new FetchDeliveryDetails();
      $itemDetailsArray = $deliveryHander-&gt;getAllDeliveryDetails($selectedItemName);
      foreach ($itemDetailsArray as $valuesArray) {
          $itemNameValue = $valuesArray['itemName'];
          $itemDescriptionValue = $valuesArray['itemDescription'];
          $ownerFirstname = $valuesArray['firstName'];
          $ownerLastname = $valuesArray['lastName'];
          $dateAdded = $valuesArray['dateAdded'];
          $deliveryDate = $valuesArray['deliveryDate'];
          $deliveryAddress = $valuesArray['deliveryAddress'];
          $deliveryLatitude = $valuesArray['deliveryLatitude'];
          $deliveryLongitude = $valuesArray['deliveryLongitude'];
          $assignedAgent = $valuesArray['assignedAgentId'];
          if ($assignedAgent == 0) {
              $assignedAgent = "-";
          }
          echo "&lt;table border=\"1\" align=\"left\" class =\"collection\"&gt;\n";
          echo "&lt;tr&gt;\n";
          echo "&lt;td &gt;Item Name:&lt;b&gt;$itemNameValue&lt;/td&gt;\n";
          echo "&lt;/tr&gt;\n";
          echo "&lt;tr&gt;\n";
          echo "&lt;td&gt;Item Description: &lt;b&gt;$itemDescriptionValue&lt;/td&gt;\n";
          echo "&lt;/tr&gt;\n";
          echo "&lt;tr&gt;\n";
          echo "&lt;td&gt;Owner Name: &lt;b&gt;$ownerFirstname $ownerLastname&lt;/td&gt;\n";
          echo "&lt;/tr&gt;\n";
          echo "&lt;tr&gt;\n";
          echo "&lt;td&gt;Date Added: &lt;b&gt;$dateAdded&lt;/td&gt;\n";
          echo "&lt;/tr&gt;\n";
          echo "&lt;tr&gt;";
          echo "&lt;td&gt;Delivery Date: &lt;b&gt;$deliveryDate&lt;/td&gt;";
          echo "&lt;/tr&gt;";
          echo "&lt;tr&gt;";
          echo "&lt;td&gt;Delivery Address: &lt;b&gt;$deliveryAddress&lt;/td&gt;";
          echo "&lt;/tr&gt;";
          echo "&lt;tr&gt;";
          echo "&lt;td&gt;Assigned Agent: &lt;b&gt;$assignedAgent&lt;/td&gt;";
          echo "&lt;/tr&gt;";
          echo "&lt;/table&gt;";
          echo "&lt;div id=\"googleMap\" style=\"width:500px;height:380px;\"&gt;&lt;/div&gt;";
      }
  }
  if (isset($_POST['agentList'])) {
  
  }
  ?&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I almost forgot, this is my first PHP application, in fact my first web application. So please go easy on me. Point out other errors also, but please stick to the question.</p>