How to add unique id's to dynamically added controls(Asp.net MVC)
<p>I'm pretty new to Javascript, and I was wondering how to add unique id's to my generated HTML textboxes. I'm currently using this script to create textboxes:</p>

<pre><code>$(document).ready(function () {
    var tbId = 'expense';
    var chkId = 'Mastercard';


    $("#txt").click(function () {

        var br = document.createElement("br");
        var ctrl = $('&lt;input/&gt;').attr({ type: 'text', name: 'text', value: 'Indskriv udgift', id: tbId }).addClass("form-control tb_Id");
        var ctrl2 = $('&lt;input/&gt;').attr({ type: 'checkbox', name: 'chk', id: chkId }).addClass("chk chk_Id");
        $("#ExpenseBoxes").append(br, ctrl, 'Mastercard: ', ctrl2, br);
    });


});
</code></pre>

<p>And this is the HTML code to add and hold the textboxes:</p>

<pre><code>&lt;input type="button" id="txt" value="Add TextBox"/&gt;
&lt;div id="ExpenseBoxes"&gt;
&lt;/div&gt;
</code></pre>

<p>I want the textbox id's to be named "expense1, expense2, expense3 ~" but I'm not sure how to go about it.</p>