boofulls
asked on
complete this code
i use the code below to let people
enter up to 20 words into seperate
text boxes but id like it to do this....
when i hit submit it will give me a x by y grid
with checkboxes for each row col intersection
so if i enter words like this
x1 "hi"
x2 "my"
x3 "name"
and then move down to y1
y1 "will
y2 "it"
y3 "work"
i will get the following grid when i hit submit
hi my name
will [] [] []
it [] [] []
work [] [] []
the [] represent unchecked check boxes....
there should also be a submit button at the end of this grid
and when a user checks all the check boxes they desire (and amount at all....in this example they can tick 0 to 9 check boxes)
the contents are put into a file "answers.txt"
like this
hi my name
will x x x
it o o o
work o o o
(if the user checked the top three buttons)
hope its not too obscure
can someone repost my code so it will work like this
thanks
oh and please dont "answer" this question
i will accpt comments as answers!
use CGI qw(:standard);
print header,
start_html("simple submit");
print start_form,
"Enter X Value ",textfield('x1'),p,
"Enter X Value ",textfield('x2'),p,
"Enter X Value ",textfield('x3'),p,
"Enter X Value ",textfield('x4'),p,
"Enter X Value ",textfield('x5'),p,
"Enter X Value ",textfield('x6'),p,
"Enter X Value ",textfield('x7'),p,
"Enter X Value ",textfield('x8'),p,
"Enter X Value ",textfield('x9'),p,
"Enter X Value ",textfield('x10'),p,
"Enter Y Value ",textfield('y1'),p,
"Enter Y Value ",textfield('y2'),p,
"Enter Y Value ",textfield('y3'),p,
"Enter Y Value ",textfield('y4'),p,
"Enter Y Value ",textfield('y5'),p,
"Enter Y Value ",textfield('y6'),p,
"Enter Y Value ",textfield('y7'),p,
"Enter Y Value ",textfield('y8'),p,
"Enter Y Value ",textfield('y9'),p,
"Enter Y Value ",textfield('y10'),p,
submit,
end_form;
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print end_html;
enter up to 20 words into seperate
text boxes but id like it to do this....
when i hit submit it will give me a x by y grid
with checkboxes for each row col intersection
so if i enter words like this
x1 "hi"
x2 "my"
x3 "name"
and then move down to y1
y1 "will
y2 "it"
y3 "work"
i will get the following grid when i hit submit
hi my name
will [] [] []
it [] [] []
work [] [] []
the [] represent unchecked check boxes....
there should also be a submit button at the end of this grid
and when a user checks all the check boxes they desire (and amount at all....in this example they can tick 0 to 9 check boxes)
the contents are put into a file "answers.txt"
like this
hi my name
will x x x
it o o o
work o o o
(if the user checked the top three buttons)
hope its not too obscure
can someone repost my code so it will work like this
thanks
oh and please dont "answer" this question
i will accpt comments as answers!
use CGI qw(:standard);
print header,
start_html("simple submit");
print start_form,
"Enter X Value ",textfield('x1'),p,
"Enter X Value ",textfield('x2'),p,
"Enter X Value ",textfield('x3'),p,
"Enter X Value ",textfield('x4'),p,
"Enter X Value ",textfield('x5'),p,
"Enter X Value ",textfield('x6'),p,
"Enter X Value ",textfield('x7'),p,
"Enter X Value ",textfield('x8'),p,
"Enter X Value ",textfield('x9'),p,
"Enter X Value ",textfield('x10'),p,
"Enter Y Value ",textfield('y1'),p,
"Enter Y Value ",textfield('y2'),p,
"Enter Y Value ",textfield('y3'),p,
"Enter Y Value ",textfield('y4'),p,
"Enter Y Value ",textfield('y5'),p,
"Enter Y Value ",textfield('y6'),p,
"Enter Y Value ",textfield('y7'),p,
"Enter Y Value ",textfield('y8'),p,
"Enter Y Value ",textfield('y9'),p,
"Enter Y Value ",textfield('y10'),p,
submit,
end_form;
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print end_html;
ASKER
this doesnt seem to work the way id like but i thank you very much for your help
say i enter
x1 x2 x3 and y1 y2 y3
for the first 3 x and y values respectively then i should only get a 3 by 3 grid but this gives me a 10 by 10 grid!
say i enter
x1 x2 x3 and y1 y2 y3
for the first 3 x and y values respectively then i should only get a 3 by 3 grid but this gives me a 10 by 10 grid!
Hehe, i thought you could do it for yourself :-)
To manage the number of checkboxes you just have to check the length of the parameter. Here's the source code of the second script with 3 "if" statements added:
========================== ========== ====
#!/usr/local/bin/perl -w
use CGI qw(:standard);
$q = new CGI;
@x = ();
@y = ();
foreach $i(1..10)
{
push(@x, param("X".$i))
}
foreach $i(1..10)
{
push(@y, param("Y".$i))
}
print $q->header,
$q->start_html("Form Results"),
$q->h1("Form Results");
$method = "POST";
$value = "";
$action = "http://www.soften.ktu.lt/~genumind/perl/matrres.cgi";
print $q->startform($method, $action, "");
print "<br>";
foreach $i(1..10)
{
if(length($x[$i-1]) > 0) # The X Column.
{
print "| $x[$i-1] |\n";
}
}
print "<br>";
foreach $i(1..10)
{
if(length($y[$i-1]) > 0)# The Y Column.
{
print "| $y[$i-1] |\n";
foreach $j(1..10)
{
if(length($x[$j-1]) > 0)# The X Column.
{
print $q->checkbox_group(-name=> "g".$i.$j,
-values=>["n".$i.$j]);
}
}
print "<br>";
}
}
print "<br>";
print $q->submit;
print $q->reset;
print "<br>";
print $q->endform;
print $q->end_html;
========================== ========== ====
I wrote you the core. Add simple changes for yourself. Do you want experts here to write all of your software? :-)
To manage the number of checkboxes you just have to check the length of the parameter. Here's the source code of the second script with 3 "if" statements added:
==========================
#!/usr/local/bin/perl -w
use CGI qw(:standard);
$q = new CGI;
@x = ();
@y = ();
foreach $i(1..10)
{
push(@x, param("X".$i))
}
foreach $i(1..10)
{
push(@y, param("Y".$i))
}
print $q->header,
$q->start_html("Form Results"),
$q->h1("Form Results");
$method = "POST";
$value = "";
$action = "http://www.soften.ktu.lt/~genumind/perl/matrres.cgi";
print $q->startform($method, $action, "");
print "<br>";
foreach $i(1..10)
{
if(length($x[$i-1]) > 0) # The X Column.
{
print "| $x[$i-1] |\n";
}
}
print "<br>";
foreach $i(1..10)
{
if(length($y[$i-1]) > 0)# The Y Column.
{
print "| $y[$i-1] |\n";
foreach $j(1..10)
{
if(length($x[$j-1]) > 0)# The X Column.
{
print $q->checkbox_group(-name=>
-values=>["n".$i.$j]);
}
}
print "<br>";
}
}
print "<br>";
print $q->submit;
print $q->reset;
print "<br>";
print $q->endform;
print $q->end_html;
==========================
I wrote you the core. Add simple changes for yourself. Do you want experts here to write all of your software? :-)
ASKER
ok thats cool
i did that and it works thanks
just one last thing
instead of writing
n11
n12
n13 to the results file if i click the top three boxes
is it possible to write
hi my name
will it work
11 12 13
into the file
ie all the x values on the first line (each seperated by a tab )
all the y values on the second line (each sperated by a tab)
and then all the checked boxes seperated by a space
thanks
(i also have a follow up question....
ill post it here and add another 200 points.....
its easier that this.....)
i did that and it works thanks
just one last thing
instead of writing
n11
n12
n13 to the results file if i click the top three boxes
is it possible to write
hi my name
will it work
11 12 13
into the file
ie all the x values on the first line (each seperated by a tab )
all the y values on the second line (each sperated by a tab)
and then all the checked boxes seperated by a space
thanks
(i also have a follow up question....
ill post it here and add another 200 points.....
its easier that this.....)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The script file (matrix.cgi) that displays edit boxes:
==========================
#!/usr/local/bin/perl
use CGI qw(:standard);
$q = new CGI;
print $q->header,
$q->start_html("Form Demo"),
$q->h1("Form Demo");
$length = 10;
$max = 10;
$method = "POST";
$value = "";
$action = "http://www.soften.ktu.lt/~genumind/perl/matr.cgi";
print $q->startform($method, $action, "");
foreach $i(1..10)
{
$name = "X".$i;
print "Enter X Value ";
print $q->textfield($name, $value, $length, $max);
print "<br>";
}
print "<br>";
foreach $i(1..10)
{
$name = "Y".$i;
print "Enter Y Value ";
print $q->textfield($name, $value, $length, $max);
print "<br>";
}
print "<br>";
print $q->submit;
print $q->reset;
print "<br>";
print $q->endform;
print $q->end_html;
==========================
The file(matr.cgi) that receives results from the matrix.cgi file and displays a matrix of checkboxes.
==========================
#!/usr/local/bin/perl -w
use CGI qw(:standard);
$q = new CGI;
@x = ();
@y = ();
foreach $i(1..10)
{
push(@x, param("X".$i))
}
foreach $i(1..10)
{
push(@y, param("Y".$i))
}
print $q->header,
$q->start_html("Form Results"),
$q->h1("Form Results");
$method = "POST";
$value = "";
$action = "http://www.soften.ktu.lt/~genumind/perl/matrres.cgi";
print $q->startform($method, $action, "");
print "<br>";
foreach $i(1..10)
{
print "| $x[$i-1] |\n";
}
print "<br>";
foreach $i(1..10)
{
print "| $y[$i-1] |\n";
foreach $j(1..10)
{
print $q->checkbox_group(-name=>
-values=>["n".$i.$j]);
}
print "<br>";
}
print "<br>";
print $q->submit;
print $q->reset;
print "<br>";
print $q->endform;
print $q->end_html;
==========================
The file (matrres.cgi), which prints the results received from the matr.cgi file. Also, it prints results to the file as you requested.
==========================
#!/usr/local/bin/perl -w
use CGI qw(:standard);
$q = new CGI;
print $q->header,
$q->start_html("Form Results"),
$q->h1("Form Results");
open(F, "> results.txt");
foreach $i(1..10)
{
foreach $j(1..10)
{
@i = param("g".$i.$j);
if(length($i[0]) > 0)
{
print F "$i[0]\n";
print "$i[0]\n";
print "<br>";
}
}
}
print $q->end_html;
close(F)
==========================
I didn't worked on the alignment of the checkboxes. It's left for the HTML gurus :-)
You can take a look at how it works on my site at:
http://www.soften.ktu.lt/~genumind/perl/matrix.cgi
Cheers