Textbox Input stored to variable - how?

So as part of the weather app I want to have a textbox in which you can enter a location press enter (or submit) and then it is stored in a variable (which i can later add to my API callback, baby steps here)

I can’t for the life of me work out how to do it, and googling hasn’t really helped much - can anyone point me in the right direction please?

Codepen:

http://codepen.io/badhoc/pen/GjxXGj?editors=1011

ok first off either use plain js or jquery … you start of with document.get… then calling with jQuery … plus you havent loaded jquery

plus you havent stored a value in your variable city

delete the var city which is out side your function

then inside your function (im going to use jquery as its what i use)
var city = $(’#city’).val() // this assigns the value of your input to the city var

you can console.log(city) it will show in console … but you have console.log(‘city’) get rid of the

you used jquery for calling but jquery requires using # for ids or . for class
so change to $(’#city-submit’).on(‘click’, submitCity);

and now it works … Just make sure to add jquery to codepen eg click on the cog icon beside the js in the javascript section and click the quick add button and select jquery

1 Like

Thanks, really bad Monday brain today - I should have known half that stuff.