Click to See Complete Forum and Search --> : Javascript: InnerHTML Issues
Tanner8
January 7th, 2009, 09:11 PM
Hey, well I wrote a script to keep adding rows onto a table. That works, and all the fields work, the problem is extraction of data.
I have drop down menu's and such in each row, but they all turn out to have the same name because to add them, I am just using innerHtml and sticking in the code. The problem I have is that I can't figure out how to get the data of one of those dropdown menus in a specific row.
I tried something like this,
var x=document.getElementById('info').rows[0].cells;
var y=x[2].innerHTML.value;
and a bunch of other stuff along those lines, but none worked.
Any ideas?
Thanks.
PeejAvery
January 7th, 2009, 10:44 PM
Both innerHTML and value are properties, therefore there is no such thing as innerHTML.value, nor could there be value.innerHTML.
If you want to get child elements of a node you will have to use childNodes (http://www.w3schools.com/DOM/prop_node_childnodes.asp) and nextSibling (http://www.w3schools.com/dom/prop_node_nextsibling.asp).
Tanner8
January 7th, 2009, 11:24 PM
Can't figure this out, can you give an example or suggestion please?
Thanks
javajawa
January 8th, 2009, 05:02 AM
A poor solution would look something like this:
theCell = document.ge.t....rows[0].cells[2];
for (i = 0; i < theCell.childNodes.count; i++) {
if (theCell.childNodes[i].nodeName == 'SELECT') {
return theCell.childNodes[i].value;
}
}
Tanner8
January 8th, 2009, 12:30 PM
Anything I do gets me undefined. Just trying to count the childnodes is undefined for me.
var x=document.getElementById('info').rows[0].cells[2];
alert(x.childNodes.count)//Undefined
Thanks
javajawa
January 8th, 2009, 01:05 PM
1) What browser are you using
2) Does x have a value [alert(x)]
In fact, you might want to try this:
var x = document.getElementById('info');
alert(x);
x = x.rows[0];
alert(x);
x = x.cells[2];
alert(x);
x = x.childNodes;
alert(x);
x = x.count;
alert(x);
Tanner8
January 8th, 2009, 01:30 PM
This is all in firefox. Here is what is returned at each one of those steps.
[object HTMLTableElement]
[object HTMLRowElement]
[object HTMLTableCellElement]
[Object NodeList]
undefined
javajawa
January 8th, 2009, 01:39 PM
And that'd be because I've got the wrong property. Javascript uses length rather than count.
I think the rest of it should work...
Tanner8
January 8th, 2009, 01:51 PM
And that'd be because I've got the wrong property. Javascript uses length rather than count.
I think the rest of it should work...
*smacks hand on forehead
I missed that as well. Sometimes the most obvious things are the hardest to find. Anyway, works great now, thanks for your help!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.