IntelliJ Java IDE
The moose likes HTML, CSS and JavaScript and the fly likes Javascript: setting variables with selectable table issue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Javascript: setting variables with selectable table issue" Watch "Javascript: setting variables with selectable table issue" New topic
Author

Javascript: setting variables with selectable table issue

matt larkin
Greenhorn

Joined: Mar 18, 2010
Posts: 5
Hello everyone, I have had this problem for over a week and have not found a solution that will work the way I want it to.

using html I have created a selectable table, which I would like to send the index of the row to a servlet once it has been submitted.
example: if row 1 is selected then on submit the user is redirected to "productServlet?rowid="+row;

I want this variable to be set when a <tr onclick> is initiated, and changed accordingly if another row is clicked. the redirect to the servlet
also must be done in javascript as I have 3 different submit buttons that do 3 different things with the selected row. this part is sorted out
I have a function called setTarget(target) which redirects to the proper servlet depending on the value.

The problem is I am unable to get the onclick function variable in the setTarget(target) function. If I was to call a row(rowid) function inside setTarget then I would need the rowId in the first place so it wont work....

Please if anyone could help me or even point me in the right direction I would much appreciate it. I have spent 8+ hours trying to get this to work.
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

Sounds like you are making things much harder than they need to be. On the other hand, I can't really understand what you are trying to do.

Rather than a stream of consciousness -- please post the steps that you want the code to take on the click event.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
matt larkin
Greenhorn

Joined: Mar 18, 2010
Posts: 5
Well The way my team has this interface set up you simply click from a selection of products in the selectable table.

Once a product is selected you may click the modify button, the show details button, or the delete button. in each of these cases
I have a redirect to a servlet which deals with the selected row accordingly. But for this to happen I cant simply redirect when someone
clicks a row as there are multiple options to choose from. This could be done easily with a listbox but formatting is not the same and
listboxes simply look like crap.

each row has a number associated to it(0,1,2,3) and when I redirect to the servlet I need to know which row was selected, either by setting the variable in a session which I dont think is possible, or send it in the url, but I dont kno how to get that variable into a url.

hopefully that explains it well enough
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

matt larkin wrote:each row has a number associated to it(0,1,2,3)
How?

Once a product is selected you may click the modify button, the show details button, or the delete button. in each of these cases
I have a redirect to a servlet which deals with the selected row accordingly. But for this to happen I cant simply redirect when someone
clicks a row as there are multiple options to choose from.
Explain "multiple options".
matt larkin
Greenhorn

Joined: Mar 18, 2010
Posts: 5
well I set the value of the tr to the index value in my for loop which populates the table. as well I have the same list in my servlet so the referenced selection in my table matches the arraylist in my servlet.

As for multiple options I mean the 3 buttons to choose from, each goes to the same servlet but with different attribute values. If you read through my post you should understand what im trying to accomplish
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

matt larkin wrote:well I set the value of the tr to the index value
<tr> elements do not have values. What do you mean by this? Maybe you should start to show some code (Please use code tags).

As for multiple options I mean the 3 buttons to choose from, each goes to the same servlet but with different attribute values.
How does this prevent you from submitting a simple request as you stated earlier?

If you read through my post you should understand what im trying to accomplish
I'd re-evaluate your approach. Being snarky to people who are trying to help you because you are not explaining yourself well is not a winning strategy.
matt larkin
Greenhorn

Joined: Mar 18, 2010
Posts: 5
well mr Bear I solved my own problem finally. and as you have shown me, this site contains only incompetant programmers who cant understand a simple scenario. stackOverflow.com is where I shall go from now on, thank you for confirming my friends opinion on your forum as being amateur
Gregg Bolinger
Sheriff

Joined: Jul 11, 2001
Posts: 15040

matt larkin wrote:well mr Bear I solved my own problem finally. and as you have shown me, this site contains only incompetant programmers who cant understand a simple scenario. stackOverflow.com is where I shall go from now on, thank you for confirming my friends opinion on your forum as being amateur


Seeing as how you got help from SO I don't see how you solved your own problem. Obviously, the folks at SO were able to mind read a bit more than we were. Sorry about that. As for the incompetent (not spelled incompetant btw) remark, you couldn't be further from the truth. Especially with regards to Bear. All we wanted was for you to explain yourself better. But if you're happier at SO then I wish you the best of luck.


My Blog | DZone Articles
 
 
subject: Javascript: setting variables with selectable table issue
 
Threads others viewed
doubt in html table
need help with dynamic table
JSF page submitting to backing bean, even javascript validation fails...
Jsp/Javascript setting variables with selectable table issue
How to get a dynamic data table populated base on rowid selection from first data table
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture