Hi! I’m trying to make my search form work on Enter click and save the input in the variable so it can be later used in API request. But my code doesn’t seem to work, and I’m not sure what’s wrong. Here’s my code so far (I haven’t started on the API part yet, just getting the input):
$(document).ready(function(){
$("#input1").keyup(function(event){
if(event.KeyCode === 13){
$("#input1").click();
}
$("#input").on("click", function(){
var text = $("input1").val();
console.log(text);
})
})
});
Where does the $("#input") come from (I don’t see an element with #input. )? also var text = $("input1").val(); misses a #: var text = $("#input1").val();
That’s because the click handler is set inside of the keyup event. So every time a keyup event happens a new click event handler is added to $("#input1").