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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve value from onClick of a table row 1

Status
Not open for further replies.

reisende

Programmer
Mar 16, 2004
74
US
Hello everybody,

What I'm trying to do is difficult to sum up in a subject line so I'll just start with the nuts and bolts.

I am currently designing a JSP page that will retrieve a list of customers and display them in a data-grid type table layout.

The specs call for tabs to be placed at the top of the table which will allow the user to view specific info about a customer they have selected from the table (by onClick of the table row).

What I would like to do is to somehow take the unique database ID # of each customer and pass it to a link for the "Customer Details" tab. Basically, you click a record row and the tab is given a link something like view_customer.jsp?id=346.

I've been toying around a little, but must admit I don't have a clue on this one.

Here's what I've started if it will help any:

Code:
for( int x = 0; x < patientList.length; x++ ) {
    out.write("<tr>");
    out.write("  <td class=\"gridColumn\">"+patientList[x].getPTID()+"<input type=\"hidden\" name=\"ptNum\" id=\"ptNum\" value=\""+patientList[x].getPTNO()+"\"></td>");
    out.write("  <td class=\"gridColumn\">"+patientList[x].getPTLNAME()+"</td>");
    out.write("  <td class=\"gridColumn\">"+patientList[x].getPTFNAME()+"</td>");
    out.write("  <td class=\"gridColumn\">"+patientList[x].getPTADD1()+"</td>");
    out.write("  <td class=\"gridColumn\">"+patientList[x].getPTCITY()+"</td>");
    out.write("  <td class=\"gridColumn\">"+patientList[x].getPTSTATE()+"</td>");
    out.write("  <td class=\"gridColumn\">"+patientList[x].getPTZIP()+"</td>");
    out.write("</tr>");
  }

As you can see I was trying a hidden form field to store the ID # (PTNO), but I don't know if that will do any good.

Any suggestions you all may have would be greatly appreciated and rewarded with many stars.

Thanks.
 
If your tab has a link in it, with an ID of, for example, "myTab":

Code:
<a href="javascript:alert('You need to select a row first!');" id="myTab">Click here to dance the Agadoo</a>

then you could skip the input field, and just set the URL directly:

Code:
<td onlick="document.getElementById('myTab').href = 'view_customer.jsp?id=' + patientList[x].getPTID();" ...>

Note the default alert if no row is selected. I thought that would be a nice touch ;-)

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks, Dan. That looks promising. I'll give it a try tomorrow and report back.
 
OK, that worked! Thanks for your time and reply, Dan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top