I want to add the amount put in a input field to a ul as list items.
I tried this but i can’t come further then this:
<body>
<input type="text" name="" id="txtNaam" placeholder="voer een getal in">
<div id="divResult"></div>
<ul></ul>
<script>
$(document).ready(() => {
var txtNaam = $('#txtNaam')
$(document).on('click', function () {
txtNaam.on('keypress', function (e) {
var key = e.which
if (key === 13) {
$('ul').append('<li>' + txtNaam.val() + '</li>');
}
})
})
})
</script>
</body>
So with txtNaam.val() if i write like 3 eggs for example in the txtNaam input field then eggs is added 3 times, is what i want to do.
Thanks already!
2
Answers
Try This
You need to click
enter key
two times to check the snippet.You can use
Regular Expressions
to extract number string from the input value. Then parse it to int and use afor
loop to carry the duplication.