Solved

populate a table with resultset then create a hyperlink in the first cell so that user can click and select row data to populate textfield

Posted on 2006-06-28
5
1,786 Views
Last Modified: 2010-05-18
Good day to all. Urgent question:

I know how to dynamically populate a table with the results of a database select statement.  The issue is that after I populate the table, I also want to dynamically create a hyperlink in the first cell of each row so that the user can select this hyperlink.  By clicking on the hyperlink, the entire contents of the row will be placed into textfields located above the table so that the user can then make modification to update database.

This is something like the functionality given in a flexgrid where rows can be selected and textfield populated.

Thanks  
0
Comment
Question by:phaidra
5 Comments
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 168 total points
ID: 17007003
its more of a javascript function then a jsp...

following script should help..

function selectValue(row,param)
{
 var parms=param.split(',');
 var mycells=row.cells;
 for(i=0;i<parms.length;i++)
 {
       document.getElementById(parms[i]).value=mycells[i].innerText;
 }

& in the table where you are making a link.. put this function..

as onclick=selectValue(this.parentNode,textfield1,textfield2,...);
0
 
LVL 3

Assisted Solution

by:w0lver
w0lver earned 166 total points
ID: 17010388
I have done it where each link contains a URL with all the items in the table as parameters, i.e.
     edit.jsp?field1=blah&field2=blahblah&field3=yadda


As so on, make sure you concert any of the text into URL friendly strings...

Then in each text box put the value from the URL string in the box:
     <%
     String field1 = "";
     try {
          field1 = request.getParameter("categoryName");
     } catch (NullPointerException npe) {
             field1 = "";
     }
     request.setAttribute("field1", field1);
     %>

Then for each form field:
 <input type="text" size="5" name="field1" value="<c:out value="${field1}"/>">

And you would do you link the same way:
     < a href="edit.jsp?field1=<c:out value="${field1}"/>">Link<a/>

0
 

Assisted Solution

by:gotekareddy
gotekareddy earned 166 total points
ID: 17029761
Hi,

Its better to put the Resultset results in a HashMap and put that in request object.

in the page where you want to populate the table with the results you simply iterated the hashmap and for the first colum give and hyperlink and onclick of that call a javascript function.

like :

1) get the Resultset and while iterating the resultset only u put the values in the HashMap with an appropriate key.

2) put that hashmap in the request like
request.setAttribute("Somename",map);

3) get the hashmap from the request. like

HashMap map = request.getAttribute("some name");
String javavariable1 = (String)map.get("somekey1");
String javavariable2 = (String)map.get("somekey2");


4) iterate the hashmap in a table and give the first colum as hyperlink and onclick call a javascript function like :

5) Function a()
{
document.forms[0].fieldname1.value = '<%=javavariable1%>'
document.forms[0].fieldname2.value = '<%=javavariable2%>'
}

thats it,
hope this satisfies ur requirement.. any clarifications send a comment.
cheers.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exception creating bean of class 5 205
Jquery - parsing the results returned from webmethod 1 118
eclipse buid path vs tomcat lib path 10 34
running on tomcat not jboss eap 7.0 3 19
The business world is becoming increasingly integrated with tech. It’s not just for a select few anymore — but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and it’s likely…
The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question