file listing within an html select box

Discussion in 'Javascript' started by brett, Feb 22, 2005.

  1. brett

    brett Guest

    On my website I have a directory filled with possible files that a user can
    select to download. Rather than going to the directory itself to download,
    I'd like the user to be able to select a single file from a select box
    embedded on an html page. I'm looking for a way that I can use javascript to
    do this for me. I know that perl could get these filenames for me easily,
    but is javascript able to put these into a select box once I have Perl parse
    the directory? Is this insecure or is there a better way to do this?

    Thanks for your help,
    Brett.
     
    brett, Feb 22, 2005
    #1
    1. Advertising

  2. brett

    Grant Wagner Guest

    "brett" <> wrote in message
    news:...
    > On my website I have a directory filled with possible files that a
    > user can
    > select to download. Rather than going to the directory itself to
    > download,
    > I'd like the user to be able to select a single file from a select box
    > embedded on an html page. I'm looking for a way that I can use
    > javascript to
    > do this for me. I know that perl could get these filenames for me
    > easily,
    > but is javascript able to put these into a select box once I have Perl
    > parse
    > the directory? Is this insecure or is there a better way to do this?


    If you are using Perl to parse the directory, use it to populate the
    <select> as well. Parsing the list of files using Perl, then using Perl
    to output client-side JavaScript that can populate a <select> is an
    extra step and places a requirement on your end-user to have JavaScript
    enabled.

    print "content-type: text/html\n\n";
    if (opendir(DIR, "$full_path"))
    {
    @files = grep(/^[^\.]|[^\.\.]$/, readdir(DIR));
    closedir(DIR);

    @files = sort(@files);

    print "<select name=\"mySelect\">\n";
    for $filename (@files)
    {
    print "<option value=\"" . $filename . "\">" . $filename .
    "</option>\n";
    }
    print "</select>\n";
    }

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
     
    Grant Wagner, Feb 22, 2005
    #2
    1. Advertising

  3. brett

    brett Guest

    Grant,

    OK, that makes sense and I think the resulting code will be simpler.

    Lets just assume for a moment that I am a windows programmer who understands
    Perl, but have never added more than a form to a webpage. How would I
    include the output of this perl script in my webpage?

    Thanks,
    Brett.

    "Grant Wagner" <> wrote in message
    news:rDMSd.214$...
    > "brett" <> wrote in message
    > news:...
    > > On my website I have a directory filled with possible files that a
    > > user can
    > > select to download. Rather than going to the directory itself to
    > > download,
    > > I'd like the user to be able to select a single file from a select box
    > > embedded on an html page. I'm looking for a way that I can use
    > > javascript to
    > > do this for me. I know that perl could get these filenames for me
    > > easily,
    > > but is javascript able to put these into a select box once I have Perl
    > > parse
    > > the directory? Is this insecure or is there a better way to do this?

    >
    > If you are using Perl to parse the directory, use it to populate the
    > <select> as well. Parsing the list of files using Perl, then using Perl
    > to output client-side JavaScript that can populate a <select> is an
    > extra step and places a requirement on your end-user to have JavaScript
    > enabled.
    >
    > print "content-type: text/html\n\n";
    > if (opendir(DIR, "$full_path"))
    > {
    > @files = grep(/^[^\.]|[^\.\.]$/, readdir(DIR));
    > closedir(DIR);
    >
    > @files = sort(@files);
    >
    > print "<select name=\"mySelect\">\n";
    > for $filename (@files)
    > {
    > print "<option value=\"" . $filename . "\">" . $filename .
    > "</option>\n";
    > }
    > print "</select>\n";
    > }
    >
    > --
    > Grant Wagner <>
    > comp.lang.javascript FAQ - http://jibbering.com/faq
    >
    >
     
    brett, Feb 23, 2005
    #3
  4. brett

    J. J. Cale Guest

    > Lets just assume for a moment that I am a windows programmer who
    understands
    > Perl, but have never added more than a form to a webpage. How would I
    > include the output of this perl script in my webpage?


    As Grant explained you do it on the server. No javascript necessary. Grant's
    example is pure and simple cgi.
    One way is:
    Create an html page exactly the way you want the client to see it using a
    <select> to display the file names.

    Copy everything in the html source up to (but not including) the <select> to
    a file. I use something.hdr. Copy the rest of the code after the </select>
    and save it as something.ftr.

    Now using Grant's code; the first line is the HTTP content type header. MUST
    have two linefeeds at the end unless you're outputting other headers(Cookie
    or something). Then just one :>}
    <snip>
    > > print "content-type: text/html\n\n";


    read the something.hdr file and output it on the fly to stdout

    > > if (opendir(DIR, "$full_path"))
    > > {
    > > @files = grep(/^[^\.]|[^\.\.]$/, readdir(DIR));
    > > closedir(DIR);
    > >
    > > @files = sort(@files);
    > >
    > > print "<select name=\"mySelect\">\n";
    > > for $filename (@files)
    > > {
    > > print "<option value=\"" . $filename . "\">" . $filename .
    > > "</option>\n";
    > > }
    > > print "</select>\n";
    > > }


    read something.ftr to stdout and your done.

    This will output your page as a whole to the clients machine.
    You can probably get some help from comp.infosystems.www.authoring.cgi.
    HTH
    Jimbo
     
    J. J. Cale, Feb 23, 2005
    #4
  5. brett

    brett Guest

    "J. J. Cale" <> wrote in message
    news:421c218e$1@news.012.net.il...
    > > Lets just assume for a moment that I am a windows programmer who

    > understands
    > > Perl, but have never added more than a form to a webpage. How would I
    > > include the output of this perl script in my webpage?

    >
    > As Grant explained you do it on the server. No javascript necessary.

    Grant's
    > example is pure and simple cgi.
    > One way is:
    > Create an html page exactly the way you want the client to see it using a
    > <select> to display the file names.
    >
    > Copy everything in the html source up to (but not including) the <select>

    to
    > a file. I use something.hdr. Copy the rest of the code after the </select>
    > and save it as something.ftr.
    >
    > Now using Grant's code; the first line is the HTTP content type header.

    MUST
    > have two linefeeds at the end unless you're outputting other

    headers(Cookie
    > or something). Then just one :>}
    > <snip>
    > > > print "content-type: text/html\n\n";

    >
    > read the something.hdr file and output it on the fly to stdout
    >
    > > > if (opendir(DIR, "$full_path"))
    > > > {
    > > > @files = grep(/^[^\.]|[^\.\.]$/, readdir(DIR));
    > > > closedir(DIR);
    > > >
    > > > @files = sort(@files);
    > > >
    > > > print "<select name=\"mySelect\">\n";
    > > > for $filename (@files)
    > > > {
    > > > print "<option value=\"" . $filename . "\">" . $filename .
    > > > "</option>\n";
    > > > }
    > > > print "</select>\n";
    > > > }

    >
    > read something.ftr to stdout and your done.
    >
    > This will output your page as a whole to the clients machine.
    > You can probably get some help from comp.infosystems.www.authoring.cgi.
    > HTH
    > Jimbo


    It does, but after some research i've realised our webserver allows SSIs, so
    i've just added an execute command in there to get it to work.

    Brett.
     
    brett, Feb 24, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gnarlodious
    Replies:
    4
    Views:
    17,605
    elizas
    May 5, 2010
  2. Robin
    Replies:
    2
    Views:
    174
    Robin
    Apr 9, 2004
  3. Sy Ys
    Replies:
    0
    Views:
    130
    Sy Ys
    Sep 15, 2007
  4. palmiere
    Replies:
    1
    Views:
    409
    Erwin Moller
    Feb 9, 2004
  5. rvelosoo
    Replies:
    1
    Views:
    339
    Bart Van der Donck
    Aug 13, 2008
Loading...

Share This Page