Click to See Complete Forum and Search --> : Help!!


mishkin
06-12-2006, 09:47 AM
Okay guys, I am stumped here, and could really use some help. Please take a look at this code and let me know what you think. This first block creates x text boxes in a table (depending on how many the client needs).


for(z=0; z <= key; z++)
{
setID=("pcName"+z)
createTD[z]=document.createElement("td")
TDcontent[z]=document.createElement("input")
TDcontent[z].setAttribute("type","text")
TDcontent[z].setAttribute("id",setID)
createTD[z].appendChild(TDcontent[z])
TR[z] = document.getElementById(4)
TD[z] = TR[z].getElementsByTagName("td").item((1+z))
replaced = TR[z].replaceChild(createTD[z],TD[z])
}


This loop placed in a function in the document head uses an empty table in the body as a skeleton to dynamically alter the page content. (this is a networking tool/tutorial used by tech support reps). There are multiple other similar loops in this function that create other content in the table.
After calling the function in the body (using "onchange" from a select object), the table will fill up based on the situation the rep is facing. Now the problem I'm running into is this: The rep needs to first select how many computers are in the network, and create a brief profile for each one, I want to create an object for each computer that pulls the values from the fields created by the initial function "setComputer()".

My object looks like this (reduced to only contain info on the text box created above. The "x" parameter is to indicate which computer profile you need to get the info for (0,1,2,3,...)


var name
getInfo = new Object()
getInfo.name = function(x)
{
name = document.getElementById("pcName"+x).value
return name;
}
//I can't use "return document.getElementById("pcName"+x).value" because of
//other irrelevant parts of the function taken out for this example.


Now if later in the head if I need to refer to the name in another function, it returns null. (after the table contents were populated ofcourse).

Here's the mystery, the following example works fine, and alerts the propper value.

var name
getInfo = new Object()
getInfo.name = function(x)
{
name = document.getElementById("pcName"+x).value
alert(name)
}


Why is it that I can try to return a value and it fails, but if I use the same function in the same place, except have it alert the value it works!! I've been trying to get this done for days, I hope someone can help.

mishkin
06-12-2006, 09:51 AM
Also I should mention that the function DOES return a value if it contains no mention of DOM, so the problem must be in some nuance of the document object model i'm not aware of. :/