Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

document.write(...)

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
In my html page I have dozens of lines the same, which I want to reduce
using some for loops inside script tags.

Given the html code:


This works fine on its own, but for some reason does not work when placed
inside document.write(...)

If I remove the SPAN tags and replace that with ABCDE, then:

produces a table showing ABCDE as expected.

Can anyone explain why the first line of code isn't working

Thanks very much
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. What is not working ?
2. Can you show us your document.write loop ?
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically I'm not getting any output...

My code is basically...


If I change the SPAN tags with say ABCDE , then ABCDE appears.
But nothing appears as it is.


Also, in the script, the element is set using...


Clearly this is just as sample to show you, the str value with depend on
x (loop variable), but if I can get this to work, I should be fine.

Any ideas??
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add a non breaking space inside the tag like <span>&nbsp;</span> will allow for the cell to show up. Not sure why you do not give the td an id and since it would do the same thing as your span does. Plus the ids can not repeat so in your smaple code, it is invalid since you would have multiple ids with the same value. Plus I would use "span_" + id for id since it is better than starting with a number.

Eric
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the advice, but its still not producing output.
I have simplified it quite a lot.
I have got rid of the SPAN tags, got rid of loops for now. Also I have
changed all the element IDs by adding an S to the front.

Using


in the header script, and then, in the body script...


This just produces an empty table.
How can I make it show the word "cow" in the cell of the table?

Thanks for any help
 
Sheriff
Posts: 67650
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

in the header script, and then, in the body script...



So you're trying to modify the content of an element before it exists. Think on that for a few minutes...
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to add to what Bear said, place document.getElementById("S21").innerHTML = "cow" inside an function called on window.onload.

Eric
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This message is the response to Bear Bibeault's message, the message above wasn't there as I started this message, hence this edit.


Yeh, I think you hit the nail on the head there.
I'm not exactly sure how it works...
Before I was printing a large table just in the body outside the script tags, and then in the header script, I was modifying its value.

Hmmm, is there a setElementById("...") function, or any other way around this.

I basically have 81 elements in the body of my html page, and it looks
horrible as it is, they are all the same, except for the ID. Which is why I want to use some for loops to condense it.

Any ideas, thanks.
[ February 14, 2006: Message edited by: colin shuker ]
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried Eric's suggestion, but unfortunately, the table is still
not printing out 'cow'.

I'm sure its possible. It would be a crime to write 81 lines of identical
code when you can use a loop.

Any advice is much appreciated, thanks.
reply
    Bookmark Topic Watch Topic
  • New Topic