title: How to get the parent div id in javaScript?
body: <p>I want to get the parent div id (the div class is called "col-sm-2") when selecting each option in HTML "select" tag in each div. But it always gives only the div id of latest added product at "id" alert. For example if the id of my last added product is "7", it always gives "7" as the alert.</p>
  
  <p>Here is my PHP code for getting the product id.</p>
  
  <pre><code>$jsql_ae7 = mysql_query("select request_list.product_id from request_list where request_list.product_id='{$jrowa2['id']}' and request_list.email='$visit_email'") or die(mysql_error());
  $jfeta7 = mysql_fetch_assoc($jsql_ae7);
  </code></pre>
  
  <p>Here is my HTML code. </p>
  
  <pre><code>&lt;div class="col-sm-2" id="&lt;?php echo $jfeta7['product_id']; ?&gt;"&gt;
      &lt;select id="formats_id" name="aformats" onchange="showFormat(this);"&gt;
          &lt;option value="&lt;?php echo $jrowa2['formats']; ?&gt;"&gt;&lt;?php echo $jrowa2['formats']; ?&gt;&lt;/option&gt;
              &lt;?php foreach($formats3 as $v3){  ?&gt;
                  &lt;?php if($v3 !== $jrowa2['formats']) { ?&gt;
                      &lt;option value="&lt;?php echo $v3; ?&gt;"&gt;&lt;?php echo $v3; ?&gt;&lt;/option&gt;
                  &lt;?php } ?&gt;          
              &lt;?php } ?&gt;
  
      &lt;/select&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is my javaScript code.</p>
  
  <pre><code>var showFormat = function(dd) {
      var format_value = dd.options[dd.selectedIndex].value;
      var scriptTags = document.getElementsByTagName('select');
      var id = scriptTags[scriptTags.length - 1].parentNode.id;
      alert(id);        
  };
  </code></pre>