title: How to echo the value of a select to a text box
body: <p>I have code in which I try to echo the value of a <code>select</code> with <code>onclick</code>.</p>
  
  <p>I have a <code>select</code> which is getting its data from a database. Now I want that the option I click on is echoed into the text box. But I fail.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?php
  require_once('functions.php');
  $cont = new pacra3();
  $segments = $cont-&gt;getSegment();
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Popup contact form&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="style.css"&gt;
      &lt;link rel="stylesheet" href="js/jquery-ui.css"&gt;
      &lt;script src="js/jquery-1.10.2.js"&gt;&lt;/script&gt;
      &lt;script src="js/jquery-ui.js"&gt;&lt;/script&gt;
      &lt;script&gt;
      function get_main_sector(myid){
          var id = document.getElementById("segment_id").value;
          alert(id);
          $(document).ready(function() {
              $("#segment_id")({
                  onSelect: function(Text, inst) {
                      $("#dt_title input[type='text']").val($("#dt_title input[type='text']").attr('data-title')+Text);
                  }
              })
          });
      }  
      &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;span id="spanSegmentData"&gt;
      &lt;select name="segment_id" id="segment_id" STYLE="width: 300px"  onchange="get_main_sector(this.value)"&gt;
          &lt;option value=""&gt;[--Select Segment------]&lt;/option&gt;
          &lt;?php
          if(is_array($segments) &amp;&amp; !empty($segments)) {
              foreach($segments as $segment) {
                  echo '&lt;option value="'.$segment-&gt;ID.'"';
                  echo '&gt;';
                  echo $segment-&gt;title;
                  echo '&lt;/option&gt;';
              } 
          }           
          ?&gt;
      &lt;/select&gt;
  &lt;/span&gt;
  
  &lt;span id="dt_title"&gt;
      &lt;input name="title" type="text" value=" MB | &lt;?php echo $segment-&gt;title;?&gt; | " data-title="MB | &lt;?php echo $segment-&gt;title;?&gt; | " style="width:300px"/ readonly&gt;
  &lt;/span&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>