`How to easily download multiple images with just one click``

I am looking for a way to enable users to download multiple images by simply checking the boxes next to each image and clicking a single button. Currently, I have individual download links below each image.

I have added checkboxes next to each image for selecting multiple images, but I am unsure how to proceed with enabling multiple downloads at once.

Answer №1

To optimize file transfer, I recommend compressing all files into a single file on the server side and serving it that way.

If this is not feasible, you could use JavaScript to loop through the download links as shown below:

Assume you have a basic HTML setup with three download links.

<ul>
<li>
  <input name="checkbox" value="/download1.jpg">Download Image 1
</li>
<li>
  <input name="checkbox" value="/download2.jpg">Download Image 2
</li>
<li>
  <input name="checkbox" value="/download3.jpg">Download Image 3
</li>
</ul>
<a href="#" onclick="downloadSelected()">Download</a>

Here is the corresponding JavaScript code. Please note that multiple popups may trigger browser warnings for users.

function downloadSelected() {
    $('input[type=checkbox]:checked').each(function() {
      window.open($(this).val());
    });
    return false;
}

You can see a working example in Plunker: http://plnkr.co/edit/0ERMZ4VyXzvE0iebGMfb

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

ReCaptcha: connecting to the TextBox's OnKeyDown event using script

I've been figuring out how to integrate ReCaptcha, ASP.NET, and Gaia Ajax. It was a bit of a challenge to use the ReCaptcha AJAX APIs with Gaia to fetch the data from the recaptcha_response_field text box in an AJAX postback through a patch. This was ...

"Encountered a TypeError: Cannot read property 'params

I've encountered an issue with passing the id to my product page. Despite trying various solutions and searching for answers, I still can't get it to work. Below is my index.js code: import React from "react"; import {render} from &quo ...

Is there a way for React to detect when a property on an object within an array passed as props undergoes a change in its value?

My goal is to minimize extra work by updating a property within an object in an array of objects called onMouseEnter when hovering over an ApartmentCard that displays information about a specific apartment. The challenge lies in synchronizing the Map that ...

retrieving a JSON file from a collection of objects using C#

Just starting out with C#, so please be patient with me :) I have a collection of individuals like this: List<Person> PeopleList = new List<Person>(); each Person object has three attributes: public string Name { get; set; } public string N ...

What are the implications of including jQuery on a page multiple times?

Currently, I find myself in a scenario where I am incorporating multiple ASCX files into an ASPX page. Some of these files contain the jQuery library, which means that jQuery may be included more than once depending on which ASCX files are added. Unfortun ...

Manage unexpected errors by displaying pop-up notifications

Is there a way to display an error message from my backend code in an alert box using javascript? I'm currently working with ASP.NET MVC 1.0. Thank you, Rod. ...

Notification: failed to register service worker for messaging

An issue arose during the retrieval of the token. FirebaseError: Messaging: The default service worker registration failed. Failed to register a ServiceWorker for scope http://localhost:3000/firebase-cloud-messaging-push-scopewith script http://localhost ...

Knockout.js client-side validation system

Currently working on a sophisticated client-side web application and I'm in search of the perfect framework for handling validations. I experimented with JQuery validation plugin, but unfortunately it didn't integrate smoothly with knockout.js da ...

Observables do not provide any results when used in a pipe with an image src

I recently created a custom pipe for the image src in my application: It is applied to selectors like this: <img [src]="myobject?.URL | secure" /> Here's the code snippet for the pipe: import { Pipe, PipeTransform } from '@angular/c ...

I am seeking a way to conceal list elements according to a specified string input using JavaScript

Looking at the list items inside this div: <div class="container"> <h2>Vanishing Act Game</h2> <div> <li class="list-group-item go" id="item">Door#1</li> <li class="list-group-item go" id="it ...

Is there a way to retrieve the JavaScript Console response code using Python and Selenium's execute_script method?

I am running a JavaScript fetch request in the Chrome developer console using Selenium's execute_script() function. The request performs as expected, but I want to set up a function that can verify if the response is a 403 status code. Is there any Se ...

Tips for shutting down the pop-up notification with Playwright?

Recently, I delved into the Playwright API and started working on an automation test. The test revolves around logging into a bank account and performing a specific action. However, I encountered a roadblock when a message box popped up on the bank's ...

Is there a way to trigger the second function once the first one has been completed?

When the change event occurs, I am invoking two functions. function1(); function2(); The function1() makes an ajax call. The function2() is running before function1() for some reason. Can anyone explain why this is happening? Any assistance would be ...

Advantages of utilizing GET parameters for detecting AJAX requests

Is there a specific purpose for identifying ajax requests by adding a GET parameter (such as 'ajax=1') instead of solely relying on checking the 'X-Requested-With' header on the server side? This method may be practical if there is unc ...

Styling the jQuery location picker input with background and focus effects

While working on a web app using jQuery locationpicker, I noticed that it's causing some styling issues with the input. Despite being able to adjust properties like width, padding, and border, changing the background requires using jQuery. Here is th ...

When making a variable call outside of a subscriber function, the returned value is 'undefined'

I find myself in a situation where I have to assign a value to a variable inside a subscriber function in Angular. The issue is that the variable returns 'undefined' when called outside of the Subscribe function. Here's what I'm encount ...

Six Material-UI TextFields sharing a single label

Is there a way to create 6 MUI TextField components for entering 6 numbers separated by dots, all enclosed within one common label 'Code Number' inside a single FormControl? The issue here is that the label currently appears only in the first tex ...

Code in Javascript that performs a check for pre-order traversal

I’m interested in writing a preorder traversal code in Java for JavaScript. I’ve been practicing this question on geeksforgeeks: Check if a given array can represent Preorder Traversal of Binary Search Tree This is the algorithm they provided: 1) Cr ...

Setting an interval for a specific function to trigger after a delay of 5 seconds

I'm struggling with setting an interval for the $.get ajax method in my code. Take a look at what I have so far... setInterval(function () { passFunction(jsonData); } ,5); $.get({ url: 'pass.php', success: ...

The ChromeDriver capabilities that have been configured are not maintained once the WebDriver is constructed in Node Selenium

I am currently experimenting with adding the default download path using Chrome capabilities in my code snippet below: const test = async () => { let builder = await new Builder().forBrowser("chrome"); let chromeCapabilities = builder.getC ...