Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

text input generation via Javascript / DOM

Status
Not open for further replies.

MikalAU

Programmer
Feb 6, 2003
4
AU
(I hope this is enough info!)

function LoadXML(){

var xmlord= new ActiveXObject("Microsoft.XMLDOM")
xmlord.async = "false";
xmlord.load('
if(xmlord.parseError.errorCode != 0){
window.alert("No such Reference file! Retry ");
return false;}

nodes = xmlord.documentElement.childNodes;
var numLots = xmlord.documentElement.childNodes.length-1;
for (i = 0; i < numLots ; i++)
{
var xLinenum = Linenum.nextNode;
var xBl = Bl.nextNode;
var xKg = Kg.nextNode;
var xDe = De.nextNode;
var xCa = Ca.nextNode;
var xSt = St.nextNode;
var xM = M.nextNode;
var xV = V.nextNode;
var xYl = Yl.nextNode;
var xMm = Mm.nextNode;
var xPo = Po.nextNode;
var xNk = Nk.nextNode;
var xCo = Co.nextNode;
var xCt =Ct.nextNode;
var xOt = Ot.nextNode;

// Calculations are performed here on the information
// approx 3 pages of code to perform the math calcualtions

// output as text boxes on the HTML page?
xBl.text + ' ' + xKg.text etc
}
}
}
I have a XML document that I read into memory as I read it into memory I then calculate the information and derive a value from the data stored in the XML document. As the information is read and processed I wish to output the data and the calculated result into text boxes for the user to view and for further processing and manipulation.

I am stuck and unable to think of a method to dynamically create text boxes with unique names to store my information.


Can some one point in the right direction?
 
Here's a code snippet that you might find helpful...

newTD = document.createElement(&quot;td&quot;)
newRow.appendChild(newTD)
newInput = document.createElement(&quot;input&quot;)
newInput.attachEvent(&quot;onfocus&quot;,blurIt)
Input.setAttribute(&quot;name&quot;,&quot;spaceListCAT&quot;)
newInput.setAttribute(&quot;value&quot;,document.cbr.spaceCat.value)

newInput.setAttribute(&quot;className&quot;, &quot;cat&quot;)
newInput.attachEvent(&quot;onmouseover&quot;,getOverLib)
newInput.attachEvent(&quot;onmouseout&quot;,cClick)
newTD.appendChild(newInput)
document.cbr.spaceCat.selectedIndex = 0


Let me know if you need more...
Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
mwolf - thank you
basic understanding is there - however with this script the XML remains static - it never changes.

The information is calcualted and placed on the fly to the user and not updated to the XML document.

Which I can do, this application is for commodity calculations, the XML data contains the base makeup of the commodity - the purpose of the scirpt is to use the static info, and derive the latest market appraisal from other XML databases, these update on a 10 min cycle.

So the static info is read - a appraisal is calculated , and the result needs to be displayed in screen in a text box, for the user to view. And take further action.

I can construct it using the following (long winded method):

txt = txt +&quot;<td width='6%' bgcolor='#F0F8FF' align='center'><input type='text' name='style&quot;+xL.text+&quot; size='5' value=&quot;+xSt.text+&quot; style='font-size: 1em'></td>&quot;;

and call the document.write(txt) method, but was keen to see if I could keep the code to a minimum.

thanks in advance

 
Actually the code snippet I posted can be quite dynamic. I use it in an asp page that generates rows of input boxes on the fly. The handler then parses them using arrays. Imagine inside a loop, you generate the text box. You could assign it a unique name, id, and value. You can even assign event handlers based on whatever criteria you'd like. Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
yes it works fine, and thank you - took me a while to get it together.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top