Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a table, whitespace problem

    Working on this xml stuff farther i encountered a javascript/dom object problem. Have a partial workaround but it's not pretty on the page itself.

    The problem is when it encounters a whitespace in an xml file, it doesn't completely write out the "a href" line, it stops at the whitespace in the text. I can get around it by adding a + or %20 to the xml file in place of a space, but then it writes that to the webpage itself as well. I don't mind a symbol being in the link itself, it actually improves the response time of the script being called and accuracy. But it looks ugly on the page to have these + and %20's all over the place.

    The code that generates the table:
    Code:
    for(i = 0; i < x.length; i++)
    			{
    				var row = document.createElement('TR');
    				for(j = 0; j < x[i].childNodes.length; j++)
    				{
    					if(x[i].childNodes[j].nodeType != 1) continue;
    					var container = document.createElement('TD');
    					var theData = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
    					container.appendChild(theData);
    					if(window.ActiveXObject)
    					{
    						if(j == 1)
    						{
    							container.innerHTML = '<a href=javascript:showLoot("' + x[i].childNodes[j].firstChild.nodeValue + '")>' + x[i].childNodes[j].firstChild.nodeValue + '<\/a>';
    						}
    					}
    					else
    					{
    						if(j == 3)
    						{
    							container.innerHTML = '<a href=javascript:showLoot("' + x[i].childNodes[j].firstChild.nodeValue + '")>' + x[i].childNodes[j].firstChild.nodeValue + '<\/a>';
    						}	
    					}				
    					row.appendChild(container);
    				}
    				tmp.appendChild(row);
    			}
    In the XML file the Item field is the only one giving me issues with whitespace.

    The XML file:
    Code:
    <loots>
    	<loot>
    		<Player>Some Guy</Player>
    		<Item>Redemption</Item>
    		<Date>12-4-06</Date>
    		<Zone>Wall of Slaughter</Zone>
    	</loot>
    	<loot>
    		<Player>Other Guy</Player>
    		<Item>Cloth Tunic</Item>
    		<Date>12-5-06</Date>
    		<Zone>Greater Faydark</Zone>
    	</loot>
    	<loot>
    		<Player>Dude</Player>
    		<Item>Rock</Item>
    		<Date>12-4-07</Date>
    		<Zone>Freeport</Zone>
    	</loot>
    	<loot>
    		<Player>Some Dude</Player>
    		<Item>Rock</Item>
    		<Date>12-4-07</Date>
    		<Zone>Freeport</Zone>
    	</loot>
    </loots>

  • #2
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Put quotes around your attribute values:
    Code:
    container.innerHTML = '<a href=\'javascript:showLoot("' + x[i].childNodes[j].firstChild.nodeValue + '")\'>' + x[i].childNodes[j].firstChild.nodeValue + '<\/a>';
    dumpfi
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    or use DOM allover, and create/append the links instead of using innerHTML
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    New Coder
    Join Date
    Apr 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by dumpfi
    Put quotes around your attribute values:
    Code:
    container.innerHTML = '<a href=\'javascript:showLoot("' + x[i].childNodes[j].firstChild.nodeValue + '")\'>' + x[i].childNodes[j].firstChild.nodeValue + '<\/a>';
    dumpfi
    Thanks, that worked as intended.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •