i'm following up on a previous question I asked here
I've worked on my code and per the answers from that post, I have eliminated the error. Now, I am not getting any output to console or results from the array in my select menu where before, when I wrote this exercise without using jQuery, i was able to effectively get items into the array and display them in my select menu. In an effort to get a more complete answer I'm posting my full html and javascript/jquery code. If anyone has any input as to why my code isn't working I would appreciate it. My goal was to use jQuery (what i'm learning now) to achieve what i did with javascript alone previously. In this exercise, i'm using a user input field for users to add clients to an array on click of a button. Once that button is pushed, I want my script to check the array to see if it contains the item and if it does not, then push the element into the array and display it in the selection list of existing clients.
<!DOCTYPE html>
<html>
<head>
<title>Keeper of Time</title>
<link rel="stylesheet" type="text/css" href="kot.css">
<script type ="text/javascript" src="http://code.jQuery.com/jquery-latest.min.js"></script>
</head>
<body>
<div class="navDiv">
<ul id="navButtons">
<li><a href="">Home</a></li>
<li><a href="">Clients</a></li>
<li><a href="">Entries</a></li>
<span><li><a href="">Account</a></li></span>
</ul>
</div>
<div id="errorMessage"></div>
<div id ="newCltDiv">
<input id= "newClt" type="text" placeholder="Add a new client">
<button id="addCltBtn"> Add Client</button>
</div>
<br>
<br>
<div id="cltListDiv">
<select id="cltList">
<option>Select an existing client</option>
</select>
<button id="cltSelect">Select Client</button>
</div>
<br>
<br>
<script type="text/javascript">
var clientArray = [];
var clientInput = document.getElementById("newClt");
var sel = document.getElementById("cltList");
clientArray.push("box");
$("#addCltBtn").click(function(){
var found = $.inArray(clientInput, clientArray);
if(found >= 0) {
//Element was found update errorMessage div
$(errorMessage).html("This Client Already Exists");
} else{
clientArray.push(clientInput.value);
console.log("Objects: " + clientArray.join(", "));
updateDropList(clientInput.value);
}
});
function updateDropList(value){
var opt = document.createElement('option');
opt.innerHTML = value;
opt.value = value;
sel.appendChild(opt);
}
//test
clientArray.push("soccer");
console.log(clientArray);
</body>
</html>