title: How can I create unique IDs with JavaScript?
body: <p>I have a form where a user can add multiple select boxes for multiple cities. The problem is that each newly generated select box needs to have a unique id. Can this be done is JavaScript?</p>
  <p>Here is the part of the form for selecting cities. Also note that I'm using some PHP to fill in the cities when a specific state is selected.</p>
  <pre><code>&lt;form id=&quot;form&quot; name=&quot;form&quot; method=&quot;post&quot; action=&quot;citySelect.php&quot;&gt;
  &lt;select id=&quot;state&quot; name=&quot;state&quot; onchange=&quot;getCity()&quot;&gt;
      &lt;option&gt;&lt;/option&gt;
      &lt;option value=&quot;1&quot;&gt;cali&lt;/option&gt;
      &lt;option value=&quot;2&quot;&gt;arizona&lt;/option&gt;
      &lt;option value=&quot;3&quot;&gt;texas&lt;/option&gt;
  &lt;/select&gt;
  &lt;select id=&quot;city&quot; name=&quot;city&quot; style=&quot;width:100px&quot;&gt;
      
  &lt;/select&gt;
  
      &lt;br/&gt;
  &lt;/form&gt;
  </code></pre>
  <p>Here is the JavaScript:</p>
  <pre><code>$(&quot;#bt&quot;).click(function() {
  
  $(&quot;#form&quot;).append(
         &quot;&lt;select id='state' name='state' onchange='getCity()'&gt;
             &lt;option&gt;&lt;/option&gt;
             &lt;option value='1'&gt;cali&lt;/option&gt;
             &lt;option value='2'&gt;arizona&lt;/option&gt;
             &lt;option value='3'&gt;texas&lt;/option&gt;
          &lt;/select&gt;
          &lt;select id='city' name='city' style='width:100px'&gt;&lt;/select&gt;&lt;br/&gt;&quot;
       );
  });
  </code></pre>