| Author |
Addressing dynamic table elements
|
kunal vermaa
Ranch Hand
Joined: Jun 27, 2009
Posts: 51
|
|
I have an application in which i am retreiving data from database using AJAX(i.e i am using javascript in my jsp page and forwarding the onclick request to a servlet) and a XML is send from the servlet to the jsp page.. i dont know how to extract the XML file and put the contents of the database inside a table row... please somebody explain how to do it...
i m new to AJAX..
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
AJAX is handled in the HTML / JavaScript forum. Moving there.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15362
|
|
Have you googled JavaScript parse XML
Eric
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56549
|
|
|
Please avoid posting in all uppercase, thanks.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56549
|
|
|
If you have a choice of interchange format, you might want to consider using JSON over XML. It's a lot easier to deal with in the script code.
|
 |
kunal vermaa
Ranch Hand
Joined: Jun 27, 2009
Posts: 51
|
|
|
even if i use JSON, i have to retrieve the data through DOM.. but how to put the data inside a dynamically created table..? even through JSON i can put the data only in elements of the HTML page... but i want the data to be displayed inside a table.. how to do that..?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56549
|
|
My point was that retrieving the data as JSON is a lot easier than digesting an XML construct.
kunal vermaa wrote:how to put the data inside a dynamically created table..?
The same way that you'd add it to any other part of the DOM.
even through JSON i can put the data only in elements of the HTML page
No, you can put them anywhere you want.
but i want the data to be displayed inside a table.. how to do that..?
Again, same way as anywhere else. Tables are DOM elements just like any other HTML elements.
|
 |
kunal vermaa
Ranch Hand
Joined: Jun 27, 2009
Posts: 51
|
|
ok.. i didnt know that.. but we can access Html elements through element ID.. something like this..
then how can i access a table and put value in each row or column....? please explain.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56549
|
|
|
Why do you not think that you can use id values with tables?
|
 |
kunal vermaa
Ranch Hand
Joined: Jun 27, 2009
Posts: 51
|
|
|
I havnt used id value for a table.. can you show me how its done..?? and I want to create dynamic table rows... so how i would know the id values of tables..?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56549
|
|
As you are creating the element, you can give them any id that you like. So it should be easy for you to know what the id values are since you will create them.
|
 |
kunal vermaa
Ranch Hand
Joined: Jun 27, 2009
Posts: 51
|
|
|
nobody in the javaranch have a solution for my problem...? i am very confused ..please help..
|
 |
kunal vermaa
Ranch Hand
Joined: Jun 27, 2009
Posts: 51
|
|
|
ok.. but i want the table rows to be created dynamically.. so how can i put id in them.. and can you please give an example of how to put different id for different table rows..
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56549
|
|
That greatly depends on how you are creating the elements. If you don't know how to add attributes like id to the elements you are creating, that's the next thing to learn.
By the way, posts like:
nobody in the javaranch have a solution for my problem...?
when someone has been trying to help you are just going to tick people off. Ticked off people don't feel much like helping.
|
 |
kunal vermaa
Ranch Hand
Joined: Jun 27, 2009
Posts: 51
|
|
|
i am sorry for making anybody feel that way.. please accept my apologies..
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56549
|
|
When you create the element, simply assign an id value to it that you can use later.
You might also want to consider using a library like jQuery that makes it easy to select element by criteria other than id. (and also makes it easier to create elements on-the-fly in the first place.)
|
 |
kunal vermaa
Ranch Hand
Joined: Jun 27, 2009
Posts: 51
|
|
|
that means to say that for a table only 1 id can exist..? can you tell me a better method for displaying information on as jsp page row by row..?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56549
|
|
kunal vermaa wrote:that means to say that for a table only 1 id can exist..?
Huh?
Every id needs to be unique. That has nothing to do with tables, but applies to all elements.
It might help if you explained the structure of the table and your needs for addressing it later.
It might be as simple as adding ids like "row1", "row2", "row3"...
|
 |
 |
|
|
subject: Addressing dynamic table elements
|
|
|