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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Document Objects

Status
Not open for further replies.

RussDP

Programmer
Jun 27, 2000
1
CA
I am trying to use &lt;DIV ...&gt; &lt;/DIV&gt; within Javascript, within document.write(), and later load those document objects into an array using eval.&nbsp;&nbsp;Only in NetScape, it does not seem possible.&nbsp;&nbsp;Netscape tells me the object has no properties.<br><br>Here is the code:<br><br>function putInDocumentImages() {<br> var imgFileCnt = 1;<br> var imgFileName;<br> var divStateMent;<br> var divStateMents = &quot;&quot;;<br> var imgCnt = 0;<br><br> for (imgCnt = 0; imgCnt &lt; maxImg; imgCnt++) {<br> imgFileName = imgFileBaseName + imgFileCnt + &quot;.&quot; + imgFileExtension;<br> imgFileCnt++;<br> if (imgFileCnt &gt; maxImgFile) {<br> imgFileCnt = 1;<br> }<br> divStateMents += &quot;&lt;div id=img&quot; + (imgCnt + 1)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ &quot; style='position: absolute; height: &quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ imgHeight + &quot;; width: &quot; + imgWidth<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ &quot;;'&gt;&lt;img SRC=&quot; + imgFileName + &quot; height=&quot; + imgHeight<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ &quot; width=&quot; + imgWidth + &quot;&gt;&lt;/div&gt;\n&quot;;<br> }<br> document.write(divStateMents);<br>}<br><br><br>Later on in code I try and load an array with these two functions:<br><br>function loadImageArray() {<br> var i = 0;<br><br> for (i = 0; i &lt; maxImg; i++) {<br> ImageArray<i> = new docObject(i + 1);<br> ImageArray<i>.X = initPosX(i);<br> ImageArray<i>.Y = initPosY();<br> ImageArray<i>.obj.left = ImageArray<i>.X;<br> ImageArray<i>.obj.top = ImageArray<i>.Y;<br> }<br>}<br><br>function docObject(aNumber) {<br> var rand_min;<br> var rand_max;<br><br> this.X = 0;<br> this.Y = 0;<br> this.speedMult = randomSpeed();<br><br> rand_min = FLUTTER_DIR_CHG_MIN - 1;<br> rand_max = FLUTTER_DIR_CHG_MAX - FLUTTER_DIR_CHG_MIN + 1;<br> this.FlutterDirChgRt = Math.abs(random_number(rand_min) + rand_max);<br> this.FlutterDirChgIt = 1;<br> this.FlutterDir = 1;<br><br> if (isNetscape) {&nbsp;&nbsp;&nbsp;<br> this.obj = eval(&quot;document.img&quot; + aNumber);<br> } else {<br> this.obj = eval(&quot;img&quot; + aNumber + &quot;.style&quot;);<br> }<br>}<br><br><br>In the above &quot;loadImageArray()&quot;, there will be a problem with the last image loaded.&nbsp;&nbsp;ImageArray<i>.obj.left will have no properties, although it should because of the assignment in function docObject().<br><br>I have ran similar code to this when the &quot;div&quot; statements are in the HTML body, rather than produced by the Javascript.&nbsp;&nbsp;Could this be a problem with document.write not &quot;fully&quot; updating the actual HTML document?<br><br>BTW: For some reason, this post is converting my array element into an italics tag for display.&nbsp;&nbsp;square brackets containing the letter &quot;i&quot; are not displaying in my post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top