pass javascript array to perl CGI script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nath

    #1

    pass javascript array to perl CGI script

    Please help!?
    I am new to writing html, javascript, pretty new to MySQL but quite
    proficient at writing Perl and i'm a quick learner.
    I am building a database driven website and i am a little stuck:

    I have page of results obtained from a MySQL query presented as a table (the
    first column having checkboxes for each of the rows in the table, and all
    having the name "seqs"). I have set up a javascript (connected to a "toggle
    all" checkbox) that toggles the checked status of all the checkboxes in the
    table. I have also included a submit button at the bottom of the table that
    i would like connected to a javascript that passes document.hit_fo rm.seqs as
    an argument. Now this is what i want to do, but aren't sure how to go about
    it:

    i want to loop through the argument document.hit_fo rm.seqs, and look to see
    if it's checked by using:
    for (i=0; i<argument document.hit_fo rm.seqs.length; i++) {
    if ( argument document.hit_fo rm.seqs[i] == 1 ) {

    }
    }

    If the checkbox is checked, i want to add the value associated with that
    checkbox to an array (or comma seperated list - as a string).
    I then what to pass the array/string to a cgi script, so i can use the
    variable to query a MySQL database.
    I then want the results to be saved to a file specified by the user via a
    "save as" dialog box.

    Please help!
    Any pointer, would be very helpful!

    Nathan


  • Martin Honnen

    #2
    Re: pass javascript array to perl CGI script



    Nath wrote:
    [color=blue]
    > I have page of results obtained from a MySQL query presented as a table (the
    > first column having checkboxes for each of the rows in the table, and all
    > having the name "seqs"). I have set up a javascript (connected to a "toggle
    > all" checkbox) that toggles the checked status of all the checkboxes in the
    > table. I have also included a submit button at the bottom of the table that
    > i would like connected to a javascript that passes document.hit_fo rm.seqs as
    > an argument. Now this is what i want to do, but aren't sure how to go about
    > it:
    >
    > i want to loop through the argument document.hit_fo rm.seqs, and look to see
    > if it's checked by using:
    > for (i=0; i<argument document.hit_fo rm.seqs.length; i++) {
    > if ( argument document.hit_fo rm.seqs[i] == 1 ) {
    >
    > }
    > }
    >
    > If the checkbox is checked, i want to add the value associated with that
    > checkbox to an array (or comma seperated list - as a string).
    > I then what to pass the array/string to a cgi script, so i can use the
    > variable to query a MySQL database.
    > I then want the results to be saved to a file specified by the user via a
    > "save as" dialog box.[/color]

    The usual way to pass values in a HTML form to a CGI script is by
    submitting that form e.g.
    <form action="yourper l.cgi"
    method="POST">

    <input type="checkbox" name="checkboxN ame" value="Kibology ">
    ...
    <input type="submit">
    </form>
    No script is needed, if the user clicks the submit button the checked
    checkboxes are passed to the CGI as
    checkboxName=va lue
    pairs.
    Why do you need or want anything else?
    Of course JavaScript can change the value of a form control, for
    instance if you want to pass JavaScript values to the CGI set up an
    <input type="hidden" name="hiddenInp ut">
    and sets its value
    <form onsubmit="this. hiddenInput.val ue = arrayVar.toStri ng();
    return true;"

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Nath

      #3
      Re: pass javascript array to perl CGI script

      Ok, maybe i'm off the mark totally (being new at this)...it seems obvious
      when someone points it out to you! :o)

      I'm not sure how to use the POST method, i've only used GET and i think the
      number of name/value pairs will be too great...would you bee kind enoug to
      give me a quick run through and/or links i might read?

      Thanks
      Nathan

      "Martin Honnen" <mahotrash@yaho o.de> wrote in message
      news:3fe31bcd$1 @olaf.komtel.ne t...[color=blue]
      >
      >
      > Nath wrote:
      >[color=green]
      > > I have page of results obtained from a MySQL query presented as a table[/color][/color]
      (the[color=blue][color=green]
      > > first column having checkboxes for each of the rows in the table, and[/color][/color]
      all[color=blue][color=green]
      > > having the name "seqs"). I have set up a javascript (connected to a[/color][/color]
      "toggle[color=blue][color=green]
      > > all" checkbox) that toggles the checked status of all the checkboxes in[/color][/color]
      the[color=blue][color=green]
      > > table. I have also included a submit button at the bottom of the table[/color][/color]
      that[color=blue][color=green]
      > > i would like connected to a javascript that passes[/color][/color]
      document.hit_fo rm.seqs as[color=blue][color=green]
      > > an argument. Now this is what i want to do, but aren't sure how to go[/color][/color]
      about[color=blue][color=green]
      > > it:
      > >
      > > i want to loop through the argument document.hit_fo rm.seqs, and look to[/color][/color]
      see[color=blue][color=green]
      > > if it's checked by using:
      > > for (i=0; i<argument document.hit_fo rm.seqs.length; i++) {
      > > if ( argument document.hit_fo rm.seqs[i] == 1 ) {
      > >
      > > }
      > > }
      > >
      > > If the checkbox is checked, i want to add the value associated with that
      > > checkbox to an array (or comma seperated list - as a string).
      > > I then what to pass the array/string to a cgi script, so i can use the
      > > variable to query a MySQL database.
      > > I then want the results to be saved to a file specified by the user via[/color][/color]
      a[color=blue][color=green]
      > > "save as" dialog box.[/color]
      >
      > The usual way to pass values in a HTML form to a CGI script is by
      > submitting that form e.g.
      > <form action="yourper l.cgi"
      > method="POST">
      >
      > <input type="checkbox" name="checkboxN ame" value="Kibology ">
      > ...
      > <input type="submit">
      > </form>
      > No script is needed, if the user clicks the submit button the checked
      > checkboxes are passed to the CGI as
      > checkboxName=va lue
      > pairs.
      > Why do you need or want anything else?
      > Of course JavaScript can change the value of a form control, for
      > instance if you want to pass JavaScript values to the CGI set up an
      > <input type="hidden" name="hiddenInp ut">
      > and sets its value
      > <form onsubmit="this. hiddenInput.val ue = arrayVar.toStri ng();
      > return true;"
      >
      > --
      >
      > Martin Honnen
      > http://JavaScript.FAQTs.com/
      >[/color]


      Comment

      • Martin Honnen

        #4
        Re: pass javascript array to perl CGI script



        Nath wrote:
        [color=blue]
        > Ok, maybe i'm off the mark totally (being new at this)...it seems obvious
        > when someone points it out to you! :o)
        >
        > I'm not sure how to use the POST method, i've only used GET and i think the
        > number of name/value pairs will be too great...would you bee kind enoug to
        > give me a quick run through and/or links i might read?[/color]

        If you know Perl CGI scripting you should know how to process POSTed
        form data. As far as I know Perl has a CGI module that eases the task of
        CGI programming with Perl, use that, it should be amply documented in
        the Perl documentation:

        JavaScript doesn't care about the method if you want to set the value of
        a form control, you can do that with
        document.forms. formName.elemen ts.controlName. value = arrayVar.toStri ng();



        --

        Martin Honnen
        http://JavaScript.FAQTs.com/

        Comment

        Working...