First of all, I've just started learning JavaScript so maybe some of the things you will see won't have sense at all so I would appreciate if you could be as detailed as possible.
I want to have an input text that when submitting, the value would be received by a script. When submitting I mean pressing the 'Enter' key. I'm working with the Accuweather API and I'm trying to get the key of a city (the one you write in the input field) using AJAX. This is what I've got:
HTML:
<form action="" onsubmit="getKey()">
<input type="text" class="input-style" id="search" name="City"
value="" autofocus="autofocus">
</form>
JavaScript:
var request = new XMLHttpRequest();
function getKey() {
var citySearch = *JSON link*;
var inputField = document.getElementById("search").value
citySearch += inputField
request.open('GET', citySearch);
var keyJSON = JSON.parse(request.responseText)
var key = keyJSON[0].Key
console.log(key)
}
//The console.log() at the end of the function is just for testing.
I've been doing some research and apparently I have to use PHP (which I know anything about) but I wanted to ask here if there's maybe an easier way. Thank you.