Set ID for input elements when creating them dynamically
<p>How can I set an input field ID when creating them dynamically when the user clicks a button. 
I have a text field and a combo box pair which will be created on click. So every time the user clicks and creates one pair, I need to assign them unique IDs so that these value pairs can be saved to an array for later retrieval. </p>

<pre><code>function createattr() {
    var input = document.createElement("input");
    input.type = "text";
    input.placeholder="Attribute name";
    input.className = "attr-textfield-style";
    inputval.appendChild(input);

    //Display the drop down menu

    var newDiv=document.createElement('div');
    var html = '&lt;select&gt;', attrtypes = typeGenerate(), i;
    for(i = 0; i &lt; attrtypes.length; i++) {
        html += "&lt;option value='"+attrtypes[i]+"'&gt;"+attrtypes[i]+"&lt;/option&gt;";
    }
    html += '&lt;/select&gt;';
    newDiv.className="attr-combobox-style";
    newDiv.innerHTML= html;
    inputval.appendChild(newDiv);

}
</code></pre>