I am trying to create a website where you put your names into an input, and press "calculate" and it will take a random li with that name and append it to a box. This is my HTML:
<form class="newName">
<label for="nameInput">Your Name</label>
<input class="input-md" id="nameInput" placeholder="(e.g: John Smith)">
<span class="btn-names">Enter...</span>
<span class="calculate">Calculate</span>
</form>
<div class="namesEntered">
<ul id="enteredNames"></ul>
</div>
<div class="centered">
<h1>And The Winner Is....</h1><br><br>
<span id="name" class="names">???</span>
</div>
And my JavaScript/jQuery:
$(document).ready(function(){
$('.btn-names').on('click', function(){
if ($('#nameInput').val() === ''){
alert('No names have been entered');
} else {
var $inputted_names = $('#nameInput').val();
var listed = '<li>'+ $inputted_names +'</li>';
$(listed).appendTo('ul');
$('#nameInput').val('');
}
});
$('.calculate').on('click', function(){
var tag = document.getElementsByTagName('li');
var name = tag.innerHTML;
var randomator = Math.floor(Math.random(tag) * name.length);
console.log(randomator);
});
});
You can view this example website at http://www.b3ws.com/randomator.html But it doesn't work just yet