title: How can I dynamically select input field in dynamically generated forms with Javascript/jQuery?
body: <p>When my document is ready I have 1 or more identically forms with select and two inputs that I want to show (1 of them based on select dynamically).</p>
  <p>For 1 form its pretty simple, but my problem is that forms are generated dynamically like when  I have on ready 1 form select tag is looking like this</p>
  <pre class="lang-HTML prettyprint-override"><code>&lt;button type=&quot;button&quot; class=&quot;add-document-item btn btn-success btn-sm pull-right&quot;&gt;
    &lt;i class=&quot;glyphicon glyphicon-plus&quot;&gt;&lt;/i&gt;
  &lt;/button&gt;
  &lt;select id=&quot;type&quot; class=&quot;form-control&quot;&gt;
     &lt;option value=&quot;1&quot;&gt;File 1&lt;/option&gt;
     &lt;option value=&quot;2&quot;&gt;File 2&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;div class=&quot;col-md-12 system&quot; id=&quot;system&quot;&gt;
     My YII2 active form field...                       
  &lt;/div&gt;
  &lt;div class=&quot;col-md-12 computer&quot; id=&quot;computer&quot;&gt;
     My YII2 active form field...                       
  &lt;/div&gt;
  </code></pre>
  <p>If after opening document and there is more than 1 form OR there is one and I adding more by myself dynamically, SELECT id's generating like &quot;type0&quot;, &quot;type1&quot;, &quot;type2&quot; and same is with form fields id's.</p>
  <p>So far I can only switch inputs dynamically only when 1 form is rendered</p>
  <pre class="lang-js prettyprint-override"><code>$(document).ready(function () {
    $('#computer').hide();
    $(document).on('change', '#type', function () {
       var val = $('#type').val();
       if (val == 2) {
         $('#system').show();
         $('#computer').hide();
       } else {
         $('#computer').show();
         $('#system').hide();
       }
     });
   });
  </code></pre>
  <p>My need is to change selected input for every generated form individual. I am stuck for this already for some time. Can anybody can help me?</p>