Initially, my PDF file does not get selected, except in the Internet Explorer browser

I am currently facing an issue with selecting PDF files in Internet Explorer. The process works smoothly in Google Chrome, but I encounter a problem when trying to select PDFs in IE.

Specifically, when I attempt to select a PDF for the first time in Internet Explorer, nothing happens - the file is not selected. However, if I try to select another PDF (not the first one), it works without any issues. After that initial hiccup, everything functions correctly and I can select PDFs as intended.

If you would like to see the full example and experience the issue yourself, please visit: http://jsfiddle.net/j5yeq/3/ (please test this in Internet Explorer).

Here is a snippet of my HTML code:

<div class="gallery">               
    <div class="label" style="margin:0;">
        <span class="field">PDFS:</span>
        <input type="file" name="pdfs[]" class="j_galleryp" multiple="multiple" accept="application/pdf"  />
        <div class="j_gfalsep">Select as many PDFs as you'd like</div>
        <img src="img/upload.png" class="j_gsendp" alt="Upload Cover" title="Upload Cover" style="margin:0 0 10px 10px;" />   
        <div class="label" id="test"></div> 
    </div>
</div>

This is the jQuery script used:

$('.j_gsendp').click(function(){
    $('.j_galleryp').click().change(function(){
         var allFiles = this.files;  
         var numFiles = this.files.length;

        $('.j_gfalsep').animate({width:'500'}, 500, function(){
            $(this).html('You selected <strong>'+ numFiles +'</strong> files.'); 

            for(var i = 0; i<numFiles; i++) {
                var file = allFiles[i],
                    name = file.name;
                $('#test').append('<div class="message">Give a title to pdf <strong>'+name+':</strong></div><span>Title for pdf '+name+':</span><input type="text" name="title[]" value=""/><br><br>');
             } 
            });
              this.val('');
        });
    });
});

Answer №1

Your jQuery code is encountering errors. While I don't have a solution for IE at the moment, even in Chrome and Firefox, this code is uploading PDF files twice from the second attempt onwards. I've made modifications to the jQuery to ensure it functions correctly.

$('.j_gsendp').click(function(){
    $('.j_galleryp').trigger('click');
});

$('.j_galleryp').change(function () {
    update();    
});

function update(){
    var input = $('.j_galleryp')[0];
    var allFiles = input.files;
    var numFiles = input.files.length;
    alert(numFiles);
    $('.j_gfalsep').animate({
        width: '400'
    }, 500, function () {
        $(this).html('You selected <strong>' + numFiles + '</strong> files.');
        for (var i = 0; i < numFiles; i++) {
            var file = allFiles[i],
                name = file.name;
            $('#test').append('<span class="field">Title of PDF ' + name + ':</span><input type="text" name="title[]" value="' + name + '"/><br><br>');
        }
    });
}

Ensure you use this corrected jQuery code and avoid binding event handlers within other event handlers, as this may lead to multiple bindings of the same event.

NOTE: Unfortunately, I am unable to edit the original question so I have provided this answer as a solution.

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

Using jQuery to iterate through an array and reverse its order

Is there a way to loop through an array and change the CSS background color chronologically rather than randomly? Additionally, is it possible to reverse through the same array when the back button is clicked? http://jsfiddle.net/qK2Dk/ $('#right&a ...

Using JSON parsing to dynamically create classes with preloaded background images

Today, I successfully deployed my browser game using MVC4 to my website for the first time. I am currently navigating through the differences between running the site off of localhost and running it from the actual website. My process involves loading all ...

Dealing with a 404 error when using the JQuery AJAX PUT method in ASP.NET MVC

My issue arises when attempting to update my data in ASP.NET MVC using jQuery AJAX with the PUT method. I am encountering a 404 error, indicating that my controller cannot be found. However, everything works fine when I use the GET or POST methods. What ...

What is the method for including an inner wrapper around an element in Angular?

Is there a way to create an Angular directive that adds an inner wrapper to a DOM element without replacing the inner content? I have tried implementing one, but it seems to be replacing instead of wrapping the content. (view example) Here is the HTML sni ...

Tips for customizing scroll bar padding and margin using CSS classes or IDs

I am looking to customize three different types of scrollbars with unique padding and margins. Here is the global style for my scrollbars: /* Modifying the scroll bar across the whole application */ /* width */ ::-webkit-scrollbar { width: 5px; he ...

How can I make a div blur as I scroll through the page

How can I make each item in my timeline focused one at a time as the user scrolls, instead of having all items in focus simultaneously? Any ideas or suggestions would be appreciated. Here is my fiddle and here is my code $(document).ready(function(){ ...

I have been seeking the perfect solution to seamlessly incorporate ckeditor5 with comments in my AngularJS applications. Despite extensive research, I have not come across any angularjs-specific plugins for this purpose. It

import Comments from '@ckeditor/ckeditor5-comments/src/comments'; ClassicEditor.builtinPlugins = [ Essentials, Paragraph, Bold, Italic, Image, Comments ]; I am trying to figure out how to incorporate comments into the CKEditor5 in an AngularJS ...

Is it possible for flex-grow to affect images? What steps can I take to identify any issues within my code?

<section> <div class="section-header"> <h5>Discover Our Team</h5> <h1>Meet the Experts</h1> <h5>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nesciunt, eaque.</h5> ...

Synchronizing Form Data in Angular 5: Pass and Populate Dropdowns between Components

I have developed a unique form (material dialog modal) that allows users to create an account. When the user clicks on the Register button, their created account should appear in a dropdown menu without redirecting or reloading the current page. I am facin ...

Upon the initial hover, the data added to the title tag following an Ajax call is not appearing

I am currently working on an ajax request that retrieves information such as username, email, and user_id. Once the ajax call is successful, I use jQuery to append this data to the title tag. The main issue I am facing is that the data is only displayed af ...

What measures can I take to ensure that users cannot tamper with the PayPal code?

I've integrated a "Pay Now" button from Paypal onto my website. However, there is an issue where users can easily alter the payment amount before proceeding. Below is the code PayPal has provided: <form action="https://www.paypal.com/cgi-bin/webs ...

Displaying a div when a radio button is clicked in React

I am attempting to create a functionality where clicking on one radio button will display another div in React. As a beginner in React, I have tried implementing the code below but encountered issues with hiding and displaying the content based on user inp ...

Why is my JavaScript code functioning properly on jsfiddle but failing to work when run locally?

After recently creating JavaScript code that allows for form submission using the <form> tag, I encountered an issue when trying to implement it within an HTML page. Here is a snippet of the code: <script type="text/javascript"> var m ...

retrieving the webpage's HTML content from the specified URL using AngularJS

Utilizing the $http.get('url') method to fetch the content located at the specified 'url'. Below is the HTML code present in the 'url': <html> <head></head> <body> <pre style = "word-wrap: break ...

Validation of forms using Javascript

I currently have an HTML form with JavaScript validation. Instead of displaying error messages in a popup using the alert command, how can I show them next to the text boxes? Here is my current code: if (document.gfiDownloadForm.txtFirstName.value == &ap ...

What is the method for defining the maximum stack size in a node.js environment?

I encountered an error when trying to convert a docx file to epub format. Despite increasing the stack size, the task was unsuccessful. The specific error message I received is as follows: RangeError: Maximum call stack size exceeded at Array.filter (n ...

What is the best way to access the attributes of a particular object following a triggered event?

I'm a bit unsure if my title makes sense, so allow me to explain. In a nutshell, I have 2 li elements within a ul list. What I aim for is that when one of these li elements is clicked, the text within that particular li is retrieved, and then an obje ...

Experiencing challenges accessing information from the useEffect hook in React

I'm facing some issues with my useEffect hook and I can't seem to figure out why it's not working. I've been trying to make a call to an endpoint, but it seems like I'm not getting any response back. Any help would be greatly appr ...

Utilize ES6 syntax to bring in a package as an extension of another package

To expand map projections in D3, it is recommended to import the necessary packages like so: const d3 = require("d3") require("d3-geo-projection")(d3) This allows you to access methods such as d3-geo-projection's geoAiry method fr ...

Designing motion graphics for a browser game

As I delve into learning about Node.js, Angular.js, Socket.io, and Express.js, my current project involves creating a multiplayer poker game like Texas Hold 'Em. However, despite spending a considerable amount of time browsing the internet, I have bee ...