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:
$(document).ready(function () {
var tbId = 'expense';
var chkId = 'Mastercard';
$("#txt").click(function () {
var br = document.createElement("br");
var ctrl = $('<input/>').attr({ type: 'text', name: 'text', value: 'Indskriv udgift', id: tbId }).addClass("form-control tb_Id");
var ctrl2 = $('<input/>').attr({ type: 'checkbox', name: 'chk', id: chkId }).addClass("chk chk_Id");
$("#ExpenseBoxes").append(br, ctrl, 'Mastercard: ', ctrl2, br);
});
});
And this is the HTML code to add and hold the textboxes:
<input type="button" id="txt" value="Add TextBox"/>
<div id="ExpenseBoxes">
</div>
I want the textbox id's to be named "expense1, expense2, expense3 ~" but I'm not sure how to go about it.