title: get selected product stock quantity on product page magento 2
body: <p>I am new in magento 2</p>
  
  <p>i want to get selected product stock qty using ajax.
  i am able to get selected product id by using below script in 
  <code>app/design/frontend/Sm/market/Magento_Catalog/templates/product/view/addtocart.phtml</code> file</p>
  
  <pre><code>var $ = jQuery.noConflict();
  $(window).load(function() {
      requirejs(['jquery'], function(jQuery) {
          var selected_options = {};
          jQuery('.swatch-attribute').each(function(k, v) {
              var attribute_id = jQuery(v).attr('attribute-id');
              var option_selected = jQuery(v).attr('option-selected');
              if (!attribute_id || !option_selected) {
                  return;
              }
              selected_options[attribute_id] = option_selected;
          });
          var product_id_index = jQuery('[data-role=swatch-options]').data('mageSwatchRenderer').options.jsonConfig.index;
          var found_ids = 0;
          jQuery.each(product_id_index, function(product_id, attributes) {
              var productIsSelected = function(attributes, selected_options) {
                  return _.isEqual(attributes, selected_options);
              }
              if (productIsSelected(attributes, selected_options)) {
                  found_ids += parseInt(product_id);
              }
          });
          console.log(found_ids);
          alert(found_ids);
      });
  });
  </code></pre>
  
  <p>and also able to count product qty by using this code</p>
  
  <pre><code>$product_Id = 1748;
  $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  $stockInfo = $objectManager-&gt;get('Magento\CatalogInventory\Api\StockRegistryInterface')-&gt;getStockItem($product_Id);
  $stockqty = (int)$stockInfo-&gt;getQty();
  echo $stockqty;
  </code></pre>
  
  <p>but how to pass product_id to php code dynamically?</p>