By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,341 Members | 1,532 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,341 IT Pros & Developers. It's quick & easy.

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

P: 3
I have tried with one for loop or two for loops. I've even separated
each firstChild.nodeValu 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

Expand|Select|Wrap|Line Numbers
  1. var str = 'The node list has ' + objNodeList. length + ' items.\n';
  2. for( var i = 0; i < objNodeList. length; i++ ) {
  3. str = str + "<option value=objNodeList2[ i].firstChild. nodeValue> " +
  4. (i + 1) + ': ' + objNodeList[ i].firstChild. nodeValue + "<\/option>" +
  5. '\n';

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

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

<option value=objNodeList2[ i].firstChild. nodeValue> 18: Children's
Books: Keep On Truckin'</option>
<option value=objNodeList2[ i].firstChild. nodeValue> 19: Archive: Book
Review Podcast</option>
<option value=objNodeList2[ i].firstChild. nodeValue> 20: Essay:
Admission Impossible</ option>
<option value=objNodeList2[ i].firstChild. nodeValue> 21: The Funny Pages
| Sunday Serial: The Lemur</option>
</pre>[/HTML]
Apr 11 '08 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Try this:
Expand|Select|Wrap|Line Numbers
  1. var str = 'The node list has ' + objNodeList. length + ' items.\n';
  2. for( var i = 0; i < objNodeList. length; i++ ) {
  3. str = str + "<option value='" + objNodeList2[ i].firstChild.nodeValue + "'> " +
  4. (i + 1) + ': ' + objNodeList[ i].firstChild.nodeValue + "<\/option>" +
  5. '\n';
Apr 12 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.