Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help, in posting data on dynamic created table

Status
Not open for further replies.

geffry

Programmer
Jun 26, 2002
33
US
I am creating a table dynamically (with values obtained from database ) with code as below, In each row of a table in the last field a "Reserve" button is present.

When the user clicks the reserver button the form calls another perl file, but i am not able to post the data in first field of the row, where the Reserve button was, to the perl file.

I know i am doing something wrong,but there must be a way to do it. I think when i create the table i should do something to assign value so that i can pass the data when the button is clicked.



print " <tr> ";
print " <td align=\"right\" valign=\"top\"> " . $fname1 . "</td> ";
print " <td align=\"right\" valign=\"top\"> " . $fip1 . "</td> ";
print " <td align=\"right\" valign=\"top\"> " . $ftip1 . "</td> ";
print " <td align=\"right\" valign=\"top\"> " . $fworkstation1 . "</td> ";
print " <td align=\"right\" valign=\"top\"> " . $fteam1 . "</td> ";

if ($ftester1 eq "" ) {

print " <td align=\"right\" valign=\"top\"> <INPUT type=\"submit\" value=\"Reserve\"> </td> ";


} else {
print " <td align=\"right\" valign=\"top\"> " . $ftester1 . "</td> ";
}

print " </tr> ";
 
One way to do this is to create a form for each table you are working with. In that form embed hidden fields for that entry. The submit button will then submit to the backend the values in its individual form. Something like this :

Code:
## assuming this entire block is in a loop 
##that loops through your database retrieved items
print "<form action=blablabla method=post>";
print "  <tr> ";
print "    <td align=\"right\" valign=\"top\"> " . $fname1 . "</td> ";
print "    <td align=\"right\" valign=\"top\"> " . $fip1 . "</td> ";
print "    <td align=\"right\" valign=\"top\"> " . $ftip1 . "</td> ";
print "    <td align=\"right\" valign=\"top\"> " . $fworkstation1 . "</td> ";
print "    <td align=\"right\" valign=\"top\"> " . $fteam1 . "</td> ";

if ($ftester1 eq "" ) {

   print "    <td align=\"right\" valign=\"top\"> <input type=hidden name="\"mydata\" value=\"somevalue\"><INPUT type=\"submit\" value=\"Reserve\"> </td> ";


} else {
    print "    <td align=\"right\" valign=\"top\"> " . $ftester1 . "</td> ";
}

print "  </tr> ";
print "</form>";

In that example each db items gets its own form surrounding the row. When the button is clicked 'mydata' will be passed to the backend for processing.

Maybe that helps, I hope it gets you on the right track.
 
dude

this would make your life a little easier...

Code:
#!/usr/bin/perl

print <<HERE;
  <tr>
    <td align='right' valign='top'>$fname1</td>
    <td align='right' valign='top'>$fip1</td>
    <td align='right' valign='top'>$ftip1</td>
    <td align='right' valign='top'>$fworkstation1</td>
    <td align='right' valign='top'>$fteam1</td>
HERE

if ($ftester1 eq "") {
  print "    <td align='right' valign='top'> <INPUT type='submit' value='Reserve'> </td>\n";
} else {
  print "    <td align='right' valign='top'>$ftester1</td>\n";
}
print "  </tr>";


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top