Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

button in a table?

by jw_griffith (Initiate)
on Apr 11, 2003 at 16:46 UTC ( [id://249924]=perlquestion: print w/replies, xml ) Need Help??

jw_griffith has asked for the wisdom of the Perl Monks concerning the following question:

I am publishing a table with html. What code do I use to get information back about which specific row the user clicks on?
use CGI qw/:standard/; print "<TABLE BORDER=1>; while(@row = $sth->fetchrow_array()){ print Tr( td ( \@row)); } print </TABLE>\n";

Replies are listed 'Best First'.
Re: button in a table?
by hiseldl (Priest) on Apr 11, 2003 at 17:06 UTC

    You could create a link as a row number as your first column.

    while (@row = ...) { # include the rownum as part of the link print Tr( td( [a({-href=>"XXX".++$rownum}, "$rownum"), @row] ) + ); # Or, just the rownum with a different link #print Tr( td( [a({-href=>"XXX"}, ++$rownum), @row] ) ); }

    Update: you could replace XXX with the URL of your cgi script and add a rownum param via GET. I.e. ... [a({-href=>"http://localhost/script_to_read_rownum.cgi?rownum=".++$rownum}, $rownum), ...]

    HTH

    --
    hiseldl
    What time is it? It's Camel Time!

Re: button in a table?
by Improv (Pilgrim) on Apr 11, 2003 at 16:51 UTC
    You'll want to create a form. Take a look at the following code:
    print qq{<FORM ACTION="esias.pl?mode=renamegroup&specific=$gid">}; print qq{<input maxLength=256 size=55 name=target value="">\n}; print qq{<input type=submit name=submitter value="Do it">\n}; print qq{</FORM><BR>\n};
    This is from an application I wrote that browses complex stuff from database. The field box is probably unnecessary (but I left it in as a good example for if you later decide to do that kinda thing). The submit button code is going to be the most useful for you.

    Note that there might also be ways to do this in javascript that won't require an actual button to be present, but I don't know how to do that.

    Update: To make the values easily retrievable, replace the "Do it" value for target above with some sort of rowid, and then you can query based on that value.
Re: button in a table?
by cbro (Pilgrim) on Apr 11, 2003 at 17:20 UTC
    And as a combination of hiseldl's response and Improv's reponse...
    You could follow hiseldl's loop to give your submit buttons different names and use param() to find out which one was clicked.
      Here's a code snippet:
      my $cq = new CGI; my $targ = $cq->param('target'); if(defined($targ)) { # User gave us a target name. Do the rename and tell the use +r all's good ... }
      At the top of the program, I'm doing "use CGI", of course. And, of course, this is all in a .pl that's in my cgi-bin directory :)
        Great, That works, but take me one more step how do I get the rownum reference into the code in the script_to_read_rownum.cgi? http://localhost/script_to_read_rownum.cgi?rownum=
Re: button in a table?
by jw_griffith (Initiate) on Apr 11, 2003 at 17:04 UTC
    Ok that would publish it, what code gets info back.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://249924]
Approved by hiseldl
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-18 00:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found