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

document.getElementById();

Status
Not open for further replies.

TommyB44

Technical User
Jun 16, 2005
76
GB
Hi all

does anyone know why the "document.getElementById();" function is giving me problems, i'm pretty sure i've narrowed it down to the "document.getElementById();", using the same browser type on different computers the script shows on one but not on the other. Any ideas why ?, also would i be able to use something in place of it like "document.getAttribute();" ?. Any advise or reasoning would be good.

Thanks
 
the clock source in a js file
Code:
function clock(){
var t,x,a,d=new Date();
x=d.toDateString();
x=x.substr(0,x.length-4);
t=d.toLocaleTimeString();
a=t.split(':');
t=a[0]+':'+a[1]+'.'+a[2].substr(0,9);
iclock.innerHTML='<span style="width:100%;color:white;background:darkblue;text-align:center">'+x+t.toLowerCase()+'&nbsp;</span>';
setTimeout("clock()",1000);}

the list in a js file
Code:
var s="$o~image~data~data~data~data$f~image2~data~data~data~data";

the function

Code:
function dolist() {
    var listings = s.split("$");
    for(i=1; i<listings.length; i++){
        listing = listings[i].split("~");
        listings[i]={
            css: listing[0],
            listImage: listing[1],
            title: listing[2],
            Time: listing[3],
            age: listing[4],
            listID: listing[5]
        }
    }
   var list = document.getElementById("list");
    var txt = "<table cellSpacing=0 cellPadding=0 width='720' border=0 align=left>";
    
  for(i=1; i<listings.length; i++){
        txt += "<tr><td width=20% class="+listings[i].css+"><img src='image/"
            +listings[i].listImage+"b.jpg' height=60></td><td width=40% class="+listings[i].css+">"
            +listings[i].title+"</td><td width=15% class="+listings[i].css+">"
            +listings[i].Time+"</td><td width=15% class="+listings[i].css+">"
            +listings[i].age+"</td><td width=10% class="+listings[i].css+">"
            +listings[i].listID
            +"</td></tr>";
    }
    txt += "</table>";
    list.innerHTML = txt;
}

the html on the page

Code:
<script id="clock" src="clock.js"></script>
<script id="list" src="list.js"></script>
<body onload="dolist">
<TABLE cellSpacing=0 cellPadding=0 width="800" border=0>
<TR><TD id=iclock align=right style="font-family:arial;font-size:9pt">
</TD></TR></TABLE>

MORE HTML

<div id="list" style='width:740;height:410'>
</div><br>


MORE HTML


The strange thing is the clock works on both browsers, both browsers are IE and i've tested it on firefox, works fine, but for some unknown reason on one of the p.c's (IE) it doesn't show the table TR TD's and doesn't write into the DIV at all. i'm not sure but it seems to be the "document.getElementById("list")", if i was to use document.write i'd see it in both computers, but that doesn't really help considering it needs to be wrote to the div tag so not to mess with the rest of the page.
i've never known two of the same browser types to act like the before when both have javascript enabled.

Thanks for reading.
 
I think it's because you have got two element with id = "list".
that is the script and your listbox.

Try to change the id in the script to: listscript or something else.
 
Hi,

No, not anymore, I've removed them and I still get the same problem.
 
I wish there was one, it's as if javascript is disabled, even though it isn't.
 
if you put:
alert (txt);

right before this:

list.innerHTML = txt;

Did you get the popup of the HTML?
 
>[tt]<body onload="dolist">[/tt]
[tt]<body onload="dolist[red]()[/red]">[/tt]

 
Technically:
[tt]<body onload="dolist()[red];[/red]">[/tt]

It is, after all, Javascript code; and javascript statements are supposed to end with a semicolon.




Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Sorry about the delayed reaction, but the computer that it doesn't work on is my brothers and i'll need him to be home to test the alert(txt);, i'll get back to you as soon as i find out.
ps. that was a typo i am using "<body onload="dolist();">"
overwise i doubt it would even be working on my p.c

thanks for the replies so far.
 
*oherwise*

the answer to the "alert(txt);" was nothing happened, no alert message at all.

i'm as confused now as ever.
 
thats the whole point, he's not getting errors, it just doesn't load on he's p.c that is using the same browser type with javascript enabled. works fine with my p.c though.
 
Is there a URL we can try this out at? If not, and you're just running it locally, check to see that your friend has the images folder with the correct images in it.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
The point sometimes is that the client more often than not get the blame for messing up their m/c whereas the application-suppliers/it-persons defend their vain face at all costs.
 
The point I was trying to make is that you posted some code, and we assumed that the code you posted (and thus the code we were spending our time debugging for you) was the code that actually had the problem.

It turned out that that wasn't the case, as you claim the errors in the code here were not in the "real" source. The only way those errors could have got in is, if instead of copying / pasting the script, you manually typed it, or edited it after pasting it (paste operations don't arbitrarily edit code, after all).

So... what I was trying to get at was... how many other errors did you introduce in the script that we're working on that are not in the "real" script.

This is why I asked for a URL. Or maybe you could paste the real code without editing it?

Hope this clarifies things,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi,

I understood your reasons completely, it was Tsuji that questioned the "points", but i'll answer that anyway,
yes i did edit then paste it in. The reason for that is because it contained personal user information and i'm sure you'll understand that i can't be pasting that in a public forum. the site it is running on is passworded and i can not give that either, so i was left with little option. having said all that i hope you know that i'm gratefull for everybodies help whether or not it resolves the problem.
In answer to Tusji, out of 15 users that have ran the script only one (my brother) has had a problem running it, all the html on the page before and after the script and even the the js clock at the top of the screen works fine, when all fingers point to the client being the the problem then maybe it is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top