title: Print Select Option Using Ajax, Jquery and a PHP Echo
body: <p>I have looked throughout Stackoverflow and seen numerous examples of this but none give the answer how to echo. I am have a select dropdown that is on a page called testing.php:</p>
  
  <pre><code>&lt;form id="projects" action="project-add.php" method="POST"&gt;
  &lt;select name="territory" id="territory"&gt;
  &lt;option value="Australia"&gt;Australia&lt;/option&gt;
  &lt;option value="Argentina"&gt;Argentina&lt;/option&gt;
  &lt;/select&gt;
  
  // A fair few more form fields here
  
  &lt;input type="submit" value="Submit Project"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I now need whatever is selected here to be available to echo as a php variable later down the form without the need to press a button.</p>
  
  <p>I have the following script in the :</p>
  
  <pre><code>&lt;script type='text/javascript'&gt;//&lt;![CDATA[ 
  $(window).load(function(){
  $('#territory').change(function(e) {
      e.preventDefault();
      var selectedOption = $(this).find('option:selected');
      $('#territory option').removeAttr('selected');
      $(selectedOption).attr('selected','selected');
      var selectedOptionValue = $(selectedOption).val();
      var selectedOptionText = $(selectedOption).text();
  
  
      $.ajax({
      url: 'testing.php', 
      type: 'POST', 
      data: {data : selectedOptionText},
      dataType: 'text',
      success: function(data){ }
   });
   });//]]&gt;
  
  
   });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>I would then like to print:</p>
  
  <pre><code>&lt;? echo $_POST['data']; ?&gt;
  </code></pre>
  
  <p>But this isn't working.  Your help would be appreciated.</p>
  
  <p>Thanks in advance</p>