I'm struggling to dynamically add table elements and form elements in an HTML page. My goal is to automatically add input boxes with labels when a user enters a number in the input box without having to click any button. I believe using the 'keyup' event handler should help me achieve this, but I am having trouble implementing it in my code. Can someone please assist me by correcting my code or suggesting an alternative solution for my requirements?
HTML CODE:
<form>
<input type="number" id="teamMemNum">
</form>
<table id="memNameTable"></table>
JAVASCRIPT:
<script type="text/javascript">
$(document).ready(function(){
$("#teamMemNum").on('keyup', function(){
var num = $("#teamMemNum").val();
var markup = "<tr><td><label for='memName'>Enter name: </label></td><td><input type='text' name='memName' id='memName'></td><td></td><td></td></tr>";
for(var i = 0; i < num; i++){
$("#memNameTable tbody").append(markup);
}
});
});
</script>