Hi i am new to javascript and have looked but can't seem to solve my problem. I am looking to ask the user for a url to an image and add it to a gallery made using html and another js document. The gallery is fine just need to figure out a way to add a new img tag with the url inside it.
This is what i have so far:
function getUrl() {
var url = prompt('Enter image URL');
if (url) { // Do string and URL validation here and also for image type
return url;
} else {
return getUrl();
}`.slider image.src = getUrl();`
<form action="" method="post" class="contact" id="contact" onsubmit="return getUrl()">
<label for="name">Add Image url:</label>
<input type="submit" value="submit">
</form>
<div class="slider">
<img src="gallery/img1.jpg" alt="image 1" />
<img src="gallery/img2.jpg" alt="image 2" />
<img src="gallery/img3.jpg" alt="image 3" />
<img id="image"/>
<button class="prev"><</button>
<button class="next">></button>
</div>
If you can help in anyway that would be great, thanks.
edit: My question was i wanted to add img tags to a gallery already in the html code but by not changing the src of any photos already there and just adding the tag each time a photo was added with the url of the photo.