Learner Driver Alert!
I'm trying to transfer the search field content from the form below named variable "name" & input it into the flickr API JSON Request tags field (line 40 below). I've tried all sorts of ways of declaring the variable & can't seem to find what I'm looking for on the web. I'm guessing that its me not knowing exactly what I'm searching for.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.getJSON demo</title>
<style>
img {
height: 100px;
float: left;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<form id="search">
<p><input id="search-name" type="text" placeholder="Type Region Here"></p>
<p><input id="search-submit" type="submit" value="Search For Region"></p>
</form>
<div id="images"></div>
<script>
var name;
$("#search").submit(function(event){
event.preventDefault();
var name = $("#search-name").val();
console.log("Search Term Was: "+name);
return false;
});
$("#search").submit(function(event) {
(function() {
var flickerAPI = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";
$.getJSON( flickerAPI, {
tags: name,
tagmode: "any",
format: "json"
})
.done(function( data ) {
$.each( data.items, function( i, item ) {
$( "<img>" ).attr( "src", item.media.m ).appendTo( "#images" );
if ( i === 0 ) {
return false;
}
});
});
})();
});
</script>
</body>
</html>
Would anyone be so kind to help / put me in the right direction?