pass javascript array to perl CGI script

N

Nath

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 == 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
 
M

Martin Honnen

Nath said:
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 == 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;"
 
N

Nath

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

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 said:
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 == 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;"
 
M

Martin Honnen

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

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();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top