Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9276095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:45:12+00:00 2026-06-18T16:45:12+00:00

Complete and utter javascript newbie here with a problem fetching .pdf files from a

  • 0

Complete and utter javascript newbie here with a problem fetching .pdf files from a web server based on a partial match. I have made a program that outputs data to a webserver, and one of the components is a folder of .pdf files. I want to be able to click on a link that will pull up the corresponding .pdf file based on a value in the data table that’s generated (I’m using slickgrid for this). Each of the .pdf files contains the value that’s in the data table and serves as good query to the .pdf folder, and I’ve been successful at getting the .pdfs I want with the following code:

var value = grid.getData().getItem(row)['data'];
var locpath = window.location.pathname.substring(0,window.location.pathname.lastIndexOf('/'));
var plotsFolder = window.location.protocol + "//" + window.location.host + locpath + "/CovPlots/";
var href = plotsFolder + value + ".pdf";
return "<a href='" + href + "'>" + value + "</a>";

The catch here is that sometimes the .pdf file that’s generated is a concatenation of two or more (I’ve seen up to 4 so far) of the ‘data’ strings, separated by ‘_’ as a delimiter for reasons not worth getting into. So, if the .pdf file is ‘somestring.pdf’, I can get it without problem. However, if the .pdf file is ‘somestring_anotherstring.pdf’, I can’t figure out how to get that .pdf file if I have either ‘somestring’ or ‘anotherstring’ as the value of ‘data’.

I’ve tried a ton of different things to get some kind of lookup that I can use to pull down the correct file based on a partial match. The latest attempt is with the FilenameFilter object in javascript, but without any knowledge of javascript, I’m having a hard time to get it working. I tried to create a new function that I could call as a lookup for the .pdf URL:

function lookup() {
    File directory = new File(plotsFolder);
    String[] myFiles = directory.list(new FilenameFilter() {
        public boolean accept(File directory, String fileName) {
        return fileName.match(value);
        }
    });
}

That only seems to thrown an error. Can anyone point me in the right direction to be able to download the correct .pdf file based on a partial match? I also tried to see if there was a jquery way to do it, but couldn’t seem to find something that works. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:45:14+00:00Added an answer on June 18, 2026 at 4:45 pm

    Without support from the server, JavaScript cannot find a file from a partial filename. What you can do, however, is have a little script on the server that does the partial-filename-matching for JavaScript, and then JavaScript can ask the server to do the match, and then when it gets the match back, it can use that filename.

    If you don’t mind loading a whole index of all the PDFs at once, you could use this little Python script to generate an index in a nice, JavaScript-friendly JSON format:

    #!/usr/bin/env python
    # Create an index of a bunch of PDF files.
    # Usage: python make_index.py directory_with_pdf_files
    
    import os
    import sys
    import json
    
    
    def index(directory):
        index = {}
    
        for filename in os.listdir(directory):
            base, ext = os.path.splitext(filename)
            if ext.lower() != '.pdf':
                continue
            for keyword in base.split('_'):
                index[keyword] = filename
    
        with open(os.path.join(directory, 'index.json'), 'w') as f:
            f.write(json.dumps(index))
    
    
    if __name__ == '__main__':
        index(sys.argv[1])
    

    Then you can just load index.json with jQuery or what-have-you. When you need to find a particular PDF’s filename, you can do something like this (assuming the object loaded from index.json is in the indexOfPDFs variable):

    var href = plotsFolder + indexOfPDFs[value];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Complete C# newbie here, so cut me some slack. I have this application that
Complete PHP newbie question here, I'm trying to load up locally a dynamic PHP
Complete knockout.js newbie here. I'm having some trouble understanding how knockout.js works. Any help
Complete newbie question here: I'm just playing with C# for the first time and
Complete Haskell newbie here, my apologies.... I am trying to create a sequence of
Complete CSS newbie here who just applied the image resizing trick in the accepted
Complete LaTeX and LyX newbie here. I am currently writing a document in LyX
Complete newbie in VS and C#, I am trying to setup a web service,
Complete newbie working with jQuery and am having a bit of a problem. I
complete noob to Haskell here with probably an even noobier question. I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.