|
-
January 7th, 2009, 09:11 PM
#1
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.
-
January 7th, 2009, 10:44 PM
#2
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 7th, 2009, 11:24 PM
#3
Re: Javascript: InnerHTML Issues
Can't figure this out, can you give an example or suggestion please?
Thanks
-
January 8th, 2009, 05:02 AM
#4
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;
}
}
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
*Guarantee may not be honoured.
-
January 8th, 2009, 12:30 PM
#5
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
-
January 8th, 2009, 01:05 PM
#6
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);
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
*Guarantee may not be honoured.
-
January 8th, 2009, 01:30 PM
#7
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
-
January 8th, 2009, 01:39 PM
#8
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...
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
*Guarantee may not be honoured.
-
January 8th, 2009, 01:51 PM
#9
Re: Javascript: InnerHTML Issues
 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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|