My task is to create a JavaScript function that will add text along with a small delete icon next to it when a button is clicked. This text should be dynamically created using TextBox and Button controls on an ASP.NET C# page, then placed within a container such as a div element.
I want the end result to resemble the tags section on Stack Overflow, where tags are added by clicking a button.
Additionally, I need to retrieve these values after a post back in order to save them to a database once the user submits the page.
Thank you!
<script type="text/javascript">
function addTo(val)
{
document.getElementById('MainContent_txtbox').value = "";
var lblLink = document.createElement("span");
lblLink.appendChild(document.createTextNode(val));
document.getElementById('addItHere1').appendChild(lblLink);
}
</script>
When the button is clicked, the text is displayed within a div tag.
Label Labe3 = new Label();
Labe3.Text = "<div id=\"addItHere" + itemCounter.ToString() + "\" ></div>";