470,596 Members | 1,604 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

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_form.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_form.seqs, and look to see
if it's checked by using:
for (i=0; i<argument document.hit_form.seqs.length; i++) {
if ( argument document.hit_form.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
Jul 20 '05 #1
3 6593


Nath wrote:
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_form.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_form.seqs, and look to see
if it's checked by using:
for (i=0; i<argument document.hit_form.seqs.length; i++) {
if ( argument document.hit_form.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.


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

<input type="checkbox" name="checkboxName" 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=value
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="hiddenInput">
and sets its value
<form onsubmit="this.hiddenInput.value = arrayVar.toString();
return true;"

--

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

Jul 20 '05 #2
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" <ma*******@yahoo.de> wrote in message
news:3f********@olaf.komtel.net...


Nath wrote:
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_form.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_form.seqs, and look to see if it's checked by using:
for (i=0; i<argument document.hit_form.seqs.length; i++) {
if ( argument document.hit_form.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.


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

<input type="checkbox" name="checkboxName" 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=value
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="hiddenInput">
and sets its value
<form onsubmit="this.hiddenInput.value = arrayVar.toString();
return true;"

--

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

Jul 20 '05 #3


Nath wrote:
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?


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:
http://www.perldoc.com/perl5.8.0/lib/CGI.html
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.elements.controlName.value = arrayVar.toString();

--

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

Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Sunny | last post: by
2 posts views Thread by Augusto Cesar | last post: by
2 posts views Thread by pleaseexplaintome | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.