/    Sign up×
Community /Pin to ProfileBookmark

Whats the best way of getting elements from a table using javascript. the table is prodcued dynamicaly by hitting a button. I want to get the id value that is stored in “value” of the first colum. At present i im am trying to get use the DOM level1 but dont seem to able to get it to play ball:

function addRow(image, text, id, name)
{
var tbody = document.getElementById(“Nav”).getElementsByTagName(“tbody”)[0];
var row = document.createElement(“TR”);

var cell1 = document.createElement(“TD”);
cell1.setAttribute(“ID”, “loc”);
cell1.setAttribute(“value”, id);
cell1.innerHTML = name;

var cell2 = document.createElement(“TD”);
var inp2 = document.createElement(“INPUT”);
inp2.setAttribute(“type”,”checkbox”);
inp2.setAttribute(“value”,”remove”);
cell2.appendChild(inp2);

var cell3 = document.createElement(“TD”);
var inp3 = document.createElement(“INPUT”);
inp3.setAttribute(“type”,”button”);
inp3.setAttribute(“value”, “More Info”);
inp3.setAttribute(“name”, “More Info”);
inp3.setAttribute(“onclick”,” openindex(‘image’, ‘text’, id, ‘name’) “);
cell3.appendChild(inp3);

row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
tbody.appendChild(row);
//alert(row.innerHTML);
}

function start() {
var x = document.getElementById(‘loc’);
//stuck here
}

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 15.2006 — TD does not have an attribute [I]value[/I]. You appear to be attempting to get an illegal attribute value.
Copy linkTweet thisAlerts:
@rupert85authorMar 15.2006 — Cheers for that. But when i document.write(x) I think that i have got the cell elements as i get: [object HTMLTableCellElement]. I just not sure what the best way of getting the loc value out.
Copy linkTweet thisAlerts:
@FangMar 15.2006 — alert(x.value)
As I mentioned; it's illegal and may not return a value.
Copy linkTweet thisAlerts:
@rupert85authorMar 15.2006 — i have managed to sort it using the following code:

var elem = document.getElementById("Navb");

for (var i = elem.rows.length-1; i >= 0 ; i--) {

v = elem.rows[i].cells[1].getAttribute("value");

}

but thankyou very much for your help
×

Success!

Help @rupert85 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...