I need to make small app using html and JavaScript to search for image in given folder.
for example i have folder called /images
with f1.jpg, f2.gif, f3.png
images and html webpage with search input. when i search for f1
it should print the f1.jpg
image with <img>
tag bellow the search input.
How i can do that with html and javascript or ajax without print all images?
Html example code:
<!doctype html>
<html>
<head>
<title>Search images</title>
<script type="text/javascript">
var folder = "images/";
$.ajax({
url : folder,
success: function (data) {
$(data).find("a").attr("href", function (i, val) {
if( val.match(/\.(jpe?g|png|gif)$/) ) {
$("body").append( "<img src='"+ folder + val +"'>" );
}
});
}
});
</script>
</head>
<body>
<form>
<label>Search for image:</label>
<br />
<input type="text" name="search" placeholder="">
<button type="submit">Search</button>
<br />
<!-- Image result should appear here -->
</form>
</body>
</html>