I'm trying to append a dropdown. What I'm trying to do is to simply add another dropdown with the help of a button. the dropdown should contain same items in it as the existing dropdown. so below is my code.
This is the jquery script for condition where user can't create more than 10 dropdown box.
$("#addButton").click(function() {
if (counter > 10) {
alert("Only 10 dropdowns allowed");
return false;
}
var newDDBoxDiv = $(document.createElement('div'))
.attr("id", +counter);
newDDBoxDiv.after().html('<label>dropdown #' + counter + ' : </label>' +
'<select type="text" name="dropdown' + counter +
'" id="dropdown' + counter + '" value="" >');
newDDoxDiv.appendTo("#mb");
counter++;
});
$("#removeButton").click(function() {
if (counter == 1) {
alert("No more dropdown to remove");
return false;
}
counter--;
$("#tid" + counter).remove();
});
and below is my cshtml
<div class="editor-field" id="mb">
@Html.DropDownListFor(model => model.MC, ViewBag.lCountry as SelectList, "--select--", new{@id="tid"})
Above code doesn't work. if anyone has any suggestion on how to accomplish it, please share.
edit: buttons are below
<input type='button' value='Add' id='addButton'>
<input type='button' value='Remove' id='removeButton'>
selecttag notinput