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;
boofullsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MindoCommented:
Here's my answer to your question (i didn't post it as an answer as you asked me).

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=>"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;
========================================

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
0
boofullsAuthor Commented:
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!
0
MindoCommented:
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? :-)
0
boofullsAuthor Commented:
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.....)
0
MindoCommented:
Did it. The second script writes the x and y values, since it gets them from the first script. The third script writes the checkbox values like 11 12 13. Everything is written to the file results.txt by appending data to it.

The modified second script:
========================================
#!/usr/local/bin/perl -w
                 
use CGI qw(:standard);                
                 
$q = new CGI;                

open(F, ">> results.txt");                

@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)
  {
    print "| $x[$i-1] |\n";
    print F "$x[$i-1]\t";
  }
}
print "<br>";
 
print F "\n";

foreach $i(1..10)
{
  if(length($y[$i-1]) > 0)
  {
    print "| $y[$i-1] |\n";
    print F "$y[$i-1]\t";
    foreach $j(1..10)
    {
      if(length($x[$j-1]) > 0)
      {
        print $q->checkbox_group(-name=>"g".$i.$j,
                           -values=>[$i.$j]);
      }
    }
    print "<br>";
  }
}

print "<br>";
print $q->submit;
print $q->reset;
print "<br>";

print $q->endform;
print $q->end_html;

print F "\n";
close(F);
========================================

The modified third script:
========================================
#!/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] ";      
      print "$i[0]\n";      
      print "<br>";
    }
  }
}
print $q->end_html;
print F "\n";      
close(F);

========================================
Here the sample results.txt file:
========================================
XOne    XTwo    XThree  XFive
YOne    YTwo    YThree  YFive
11 12 13 32 33 53 55  
========================================
Hope you'll find the places where i print to the file handle "F" :-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.