sending variablies from a dynamic table

Discussion in 'Perl Misc' started by cartercc@gmail.com, Dec 7, 2005.

  1. Guest

    I have constructed a table using input from a database. It looks like
    this:

    <table>
    <tr>
    <td>Pat</td>
    <td><input type="radio" name="sex1" value="M" /> Guy<br />
    <td><input type="radio" name="sex1" value="F" /> Gal</td>
    </tr><tr>
    <td>Les</td>
    <td><input type="radio" name="sex2" value="M" /> Guy<br />
    <td><input type="radio" name="sex2" value="F" /> Gal</td>
    </tr><tr>
    <td>Sal</td>
    <td><input type="radio" name="sex3" value="M" /> Guy<br />
    <td><input type="radio" name="sex3" value="F" /> Gal</td>
    </tr>
    </table>

    The table is generated from a database where there is no data in the
    'gender' column. I cannot tell in advance how many rows will be
    generated. I will pass the data to an update script that will write the
    values to the 'gender' column. My script sends the appropriate string,
    like 'page.cgi?user=me&role=manager&sex1=M&sex2=F&sex3=F'

    I *could* use checkboxes and glob all the values together, like
    'sex=v1M;v2F;v3F', read these into a variable, split the string, read
    it into an array, and run a series of update queries (and will probably
    wind up doing this for lack of something better), but I'd really like
    to pass each value separately into its own variable, or better still,
    to pass the whole thing as an arrayref to a series of hash refs, like
    [{Pat=>'M'},{Les=>'F'},{Sal=>'F'}] ... but I don't know how to
    dynamically allocate variables in a Perl script or perhaps use a client
    side script to create and pass an array ref.

    Ideas, anyone? I really, really would appreciate it.

    CC
     
    , Dec 7, 2005
    #1
    1. Advertising

  2. Guest

    wrote:
    > I have constructed a table using input from a database. It looks like
    > this:
    >
    > <table>
    > <tr>
    > <td>Pat</td>
    > <td><input type="radio" name="sex1" value="M" /> Guy<br />
    > <td><input type="radio" name="sex1" value="F" /> Gal</td>
    > </tr><tr>
    > <td>Les</td>
    > <td><input type="radio" name="sex2" value="M" /> Guy<br />
    > <td><input type="radio" name="sex2" value="F" /> Gal</td>
    > </tr><tr>
    > <td>Sal</td>
    > <td><input type="radio" name="sex3" value="M" /> Guy<br />
    > <td><input type="radio" name="sex3" value="F" /> Gal</td>
    > </tr>
    > </table>
    >
    > The table is generated from a database where there is no data in the
    > 'gender' column. I cannot tell in advance how many rows will be
    > generated. I will pass the data to an update script that will write the
    > values to the 'gender' column. My script sends the appropriate string,
    > like 'page.cgi?user=me&role=manager&sex1=M&sex2=F&sex3=F'


    Do you really mean your script sends that strings? Or do you mean your
    script writes an html form which, when interpreted, filled out, and
    submitted, causes that string to be sent?

    >
    > I *could* use checkboxes and glob all the values together, like
    > 'sex=v1M;v2F;v3F', read these into a variable, split the string, read
    > it into an array, and run a series of update queries (and will probably
    > wind up doing this for lack of something better),


    How are you going to get an html form to make something like that? Heavy
    javascripting?

    > but I'd really like
    > to pass each value separately into its own variable, or better still,
    > to pass the whole thing as an arrayref to a series of hash refs, like
    > [{Pat=>'M'},{Les=>'F'},{Sal=>'F'}]


    Why create a bunch of hashes which only have one key-value pair each? Why
    not something more like {Pat=>'M',Les=>'F',Sal=>'F'}
    And where did Pat, Les, and Sal come from? You submitted sex1, sex2, etc,
    not actual names.

    Something like:
    my $ref= [ map {$_, $cgi->param($_)} grep /^sex\d+$/, $cgi->param() ];

    should make something like:
    { sex1=>'M', sex2=>'F', sex3=>'F' }

    (Assuming you are using CGI.pm to parse the forms and that the CGI object
    is named $cgi)

    > ... but I don't know how to
    > dynamically allocate variables in a Perl script


    Do you mean that you know nothing about symbolic references, or that you
    know nothing about any references?

    > or perhaps use a client
    > side script to create and pass an array ref.


    Yeah, that's not going to happen. Look elsewhere.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Dec 7, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Glos
    Replies:
    0
    Views:
    648
    Rick Glos
    Jul 8, 2003
  2. =?Utf-8?B?QkxpVFpXaU5H?=

    Adding dynamic LinkButton to dynamic table

    =?Utf-8?B?QkxpVFpXaU5H?=, Jul 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    734
    =?Utf-8?B?QkxpVFpXaU5H?=
    Jul 27, 2005
  3. Replies:
    0
    Views:
    1,377
  4. opius
    Replies:
    0
    Views:
    1,182
    opius
    Jun 17, 2011
  5. Kooki

    Dynamic Table with Dynamic Button inside

    Kooki, Sep 15, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    153
    Kooki
    Sep 15, 2005
Loading...

Share This Page