CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2006
    Posts
    62

    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.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    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.

  3. #3
    Join Date
    Apr 2006
    Posts
    62

    Re: Javascript: InnerHTML Issues

    Can't figure this out, can you give an example or suggestion please?

    Thanks

  4. #4
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: Javascript: InnerHTML Issues

    A poor solution would look something like this:

    PHP Code:
    theCell document.ge.t....rows[0].cells[2];
    for (
    0theCell.childNodes.counti++) {
      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.

  5. #5
    Join Date
    Apr 2006
    Posts
    62

    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

  6. #6
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    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.

  7. #7
    Join Date
    Apr 2006
    Posts
    62

    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

  8. #8
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    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.

  9. #9
    Join Date
    Apr 2006
    Posts
    62

    Re: Javascript: InnerHTML Issues

    Quote Originally Posted by javajawa View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured