Javascript For Loop displays only one of two firstChild.nodeValues in String

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neilfarah
    New Member
    • Feb 2008
    • 3

    Javascript For Loop displays only one of two firstChild.nodeValues in String

    I have tried with one for loop or two for loops. I've even separated
    each firstChild.node Valu e by a semicolon and I still get the same
    result. It will print with one of the nodeValues, but not both. I
    have double checked whether the javascript can acually read either
    nodeValues by using alert(nodeValue ) checks and it does. But when it comes to displaying it displays one or the other and not both. I've even tried creating a separate array thinking it might be due to an out of memory error. But still
    get the same result. Any suggestions are highly appreciated.

    This is the for loop

    [CODE=javascript]var str = 'The node list has ' + objNodeList. length + ' items.\n';
    for( var i = 0; i < objNodeList. length; i++ ) {
    str = str + "<option value=objNodeLi st2[ i].firstChild. nodeValue> " +
    (i + 1) + ': ' + objNodeList[ i].firstChild. nodeValue + "<\/option>" +
    '\n';[/CODE]


    This is what the page source looks like. Notice it only prints one of
    the nodeValues and not both . The nodeValue that won't display is the
    URL. Please note, this is completely interchangeable . It will print
    one or the other list of nodeValues and not both. And please note I've checked to see if both nodes are readable using alert() checks. And they are, but only one of the list of Nodes displays in the popup webpage. Please help.

    [HTML]<SELECT
    onchange="windo w. location. href=this. options[this. selectedIndex] .value">< pre>The
    node list has 21 items.
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 1: NYT > Books</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 2: NYT > Books</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 3: Books of The
    Times: The Case for Another Drug War, Against Pharmaceutical
    Marketers' Dirty Tactics</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 4: Magda Cordell
    McHale, 86, Futurist Thinker, Is Dead</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 5: For Youngsters,
    Leaps and Boundaries</ option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 6: Exhibition
    Review: A Giant's Roaring, Faintly Echoed</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 7: Western Authors
    Celebrate a Master</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 8: A $100 Million
    Donation to the N.Y. Public Library</option>

    <option value=objNodeLi st2[ i].firstChild. nodeValue> 9: Neighborhood
    Watch</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 10: What's
    Left</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 11: Woe Be
    Gone</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 12: Wild and Crazy
    Guys</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 13: Obsessed (Agog,
    Beset, Consumed, Driven, etc.)</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 14: The Wrong
    War</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 15: Hot or Not</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 16: I Feel
    Good</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 17: The
    Interrogator< /option>

    <option value=objNodeLi st2[ i].firstChild. nodeValue> 18: Children's
    Books: Keep On Truckin'</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 19: Archive: Book
    Review Podcast</option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 20: Essay:
    Admission Impossible</ option>
    <option value=objNodeLi st2[ i].firstChild. nodeValue> 21: The Funny Pages
    | Sunday Serial: The Lemur</option>
    </pre>[/HTML]
    Last edited by gits; Apr 12 '08, 09:37 AM. Reason: added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Try this:[CODE=javascript]var str = 'The node list has ' + objNodeList. length + ' items.\n';
    for( var i = 0; i < objNodeList. length; i++ ) {
    str = str + "<option value='" + objNodeList2[ i].firstChild.nod eValue + "'> " +
    (i + 1) + ': ' + objNodeList[ i].firstChild.nod eValue + "<\/option>" +
    '\n';[/CODE]

    Comment

    Working...