Recently i started working on a project, in this i have to add the text entered by user in a text box into a ul list in bootstrap. This script is in my head section
<script type="text/javascript">
function addNames(){
$( document ).ready(function() {
$("#sendButton").click(function(){
var val = $('#textbox').val();
$('<li class = "list-group-item">'+val+'</li>').appendTo('#ulList');
});
});
}
</script>
This is in my body tag
<input type="text" id="textbox"></input>
<button type="button" class="btn btn-lg btn-success" id="sendButton" onclick=addNames()>add</button>
<ul class="list-group" id="ulList"></ul>
The problem i am facing is that i have to click the add
button twice to get any output on the screen(ONLY THE FIRST TIME, then the script works properly on one click) but the output is not a desired output.
i get multiple entries of the text in the textbox, even on a single click. please help.
-thanx