View Full Version : My rows are appearing horizontally! o.O

03-22-2012, 02:46 AM
The code so far works, but the rows form horizontally rather than vertically. This is my first time working with XMLHttpRequest() so it's probably pretty sloppy. Also, when the function runs again, it creates another row above the previous row, I'll add a screen shot.

http://tinyurl.com/7c7fylb - What it looks like when I've typed "bloodb" which means everything after the return if statement has ran twice

function findCard()
str = document.getElementById("cardName").value;
if (str.length<=4)
xmlhttp=new XMLHttpRequest();
var strLng = str.length;
var x = xmlDoc.getElementsByTagName("card");
var table = document.getElementById("cardDisplay")
var newRow = table.insertRow(0)

for (i=0; i {
var resaultStr = x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue.slice(0,strLng)
if (str==resaultStr)



03-22-2012, 10:51 AM
Ok, this is exactly what your code does (given that this is actually your code, you should know it)

- newRow = table.insertRow(0) will create a new row on top of the table
- newRow.insertCell will insert a cell into the current row. You are doing that inside the loop, so you will get a lot of cells in the same row

So where is your problem? And what is the requirement?

03-22-2012, 01:15 PM
Alright I got it to work

The code actually would work, but since it's in a for loop I have to change the row index while it's in the for loop.
What was confusing me was that out side of a loop, for instance if I just had a function with just


code it would create a new row each time I ran the function. But inside a loop it just adds a cell. Still kinda strange to me.
newRow is now set to 0

03-22-2012, 04:22 PM
Good to hear you got your head around the problem!

Just thought I'd post to say that, like may, I read the post title and thought 'Well, Rows are supposed to be horizontal!' :confused: