selectable table rows in php

I've been asked to make selectable table rows for any dynamic HTML tables that are created.  Is there a way to simulate the behavior of  a regular submit button by only using rows?  Obviously once a user selects a record, the new page will display data that corresponds to the selected record-so I would need to find a way to capture that data when the new php page is generating.
boodyAsked:
Who is Participating?
 
BatalfCommented:
There are several options

1) Direct links from a row
2) Popuplate a hidden field and post a form.

Example:

<script type="text/javascript">
function redirect(id){
    document.forms[0].theID.value = id; // setting theID field of the form
    document.forms[0].submit(); // Submit form
}
</script>
<?
echo "<table>";
$res = mysql_query("select id,theName from myTable");
while($inf = mysql_fetch_array($res)){  // Listing out items in the table
    echo "<tr>";
    echo "<td><a href=\"#\" onclick=\"redirect(".$inf["id"]."');return false\">".$inf["theName"]."</td>";
    echo "</tr>\n";
}
echo "</table>";
?>
<form action="page2.php" method="post">
<input type="hidden" name="theID" value="">
</form>
</body>
</html>

Then pick up $_POST['theID'] in the "page2.php" file.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.