Link to home
Start Free TrialLog in
Avatar of prain
prainFlag for United States of America

asked on

Question on how to capture a clicked item on a table and pass to a Servlet?

Hello,

How do I capure an item clicked on a table and send it to a Servelt? For example Say I have a table like this...

   item1      item2        item3
   item4      item5        item6
   ------       ------        ------

Say I click on item5. I need to pick this item and call a Servlet so that I pass the value 'item5' to the
servlet.

Thanks
prain
Avatar of fargo
fargo

Hi,

There are two options

1) When you click on a particular item, have a onclick event , set the hidden parameter in the form with this particular value and then submit the complete form (This means refresh complete page) and the action of the form should be the servlet.

2) Use AJAX and have an action make a java call (with servlet)

fargo
Avatar of prain

ASKER

So do I have to attach an onClick event for each item in the table?
Yes, how are you getting the items in thetable? You could use a scriptlet for doing this.
Avatar of prain

ASKER

Within my servlet that prepares the table, I am having a variable. So the items that you see in the table are NOT
hard coded they are genrated dynamically. This is the line that I create each cell . the

displayName

is a java String variable.


out.println("<td>" + displayName + "</td> ");

So what I need is to pickup the value presented by t he displayName (visible in the table) and then
pass that value to a Servlet.

Thx.
Avatar of prain

ASKER

Hello,
I am increasing the points to 125.

I am getting the whole table messed up when I attach onClick or any other in each cell.

Again, here is what I want.

My table is generated by a Servlet. The Servlet has a loop within which I have this code.

out.println("<td>" + displayName + "</td> ");

where displayName is a java String variable. So when the table is created, item visible on each cell is created dynamically.

So I will have a table like this....

  item1      item2        item3
  item4      item5        item6
  ------       ------        ------

This works nice and the table is generated nicely. Now I want add some spice to that. I want to make each item a selectable item and then when selected I want to call a Servelt and I want to pass that selected item to teh servlet. Any help?
>> I want to make each item a selectable item
ok. What do u mean by selectable item?

Do you wish it to be a link?
Do you wish to add a checkbox to each item?

What exactly?

fargo
Avatar of prain

ASKER

Actually it sould go to a Servlet. We we can say it s a link.
ASKER CERTIFIED SOLUTION
Avatar of fargo
fargo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prain

ASKER

fargo,

Goodie!. I got it. Thanks for all hints. a+

prain