Javascript: InnerHTML Issues
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,
Code:
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.
Re: Javascript: InnerHTML Issues
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 and nextSibling.
Re: Javascript: InnerHTML Issues
Can't figure this out, can you give an example or suggestion please?
Thanks
Re: Javascript: InnerHTML Issues
A poor solution would look something like this:
PHP Code:
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;
}
}
Re: Javascript: InnerHTML Issues
Anything I do gets me undefined. Just trying to count the childnodes is undefined for me.
Code:
var x=document.getElementById('info').rows[0].cells[2];
alert(x.childNodes.count)//Undefined
Thanks
Re: Javascript: InnerHTML Issues
1) What browser are you using
2) Does x have a value [alert(x)]
In fact, you might want to try this:
Code:
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);
Re: Javascript: InnerHTML Issues
This is all in firefox. Here is what is returned at each one of those steps.
Code:
[object HTMLTableElement]
[object HTMLRowElement]
[object HTMLTableCellElement]
[Object NodeList]
undefined
Re: Javascript: InnerHTML Issues
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...
Re: Javascript: InnerHTML Issues
Quote:
Originally Posted by
javajawa
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!