Connecting Tech Pros Worldwide Help | Site Map

getElementById driving me crazy

pantagruel
Guest
 
Posts: n/a
#1: May 13 '07
the browser is firefox

the javascript:

function slideshowchecker(){

if(document.getElementById){alert('it works');}
slide = document.getElementById("slideX");



if(slide==null){
alert('yes2');
}

}
window.onload=slideshowchecker();

the document has a div id = slideX.
both alerts keep coming up.

here is the html

<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head><title>slideshow</title><script

src="jscripts/GTA.js" ></head><body><div class="slide" id="slideX">
grrrrrrrr

</div></body></html>

Why is slideX coming up null?

I'm really tired, I've been working from noon to 9 pm yesterday and
from 1 am to 5 am this morning.

pantagruel
Guest
 
Posts: n/a
#2: May 13 '07

re: getElementById driving me crazy


On May 13, 5:40 am, pantag
oh wait, just realized, the script is executing before the div exists
so slide is null.

ruel <rasmussen.br...@gmail.comwrote:
Quote:
the browser is firefox
>
the javascript:
>
function slideshowchecker(){
>
if(document.getElementById){alert('it works');}
slide = document.getElementById("slideX");
>
if(slide==null){
alert('yes2');
>
}
}
>
window.onload=slideshowchecker();
>
the document has a div id = slideX.
both alerts keep coming up.
>
here is the html
>
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head><title>slideshow</title><script
>
src="jscripts/GTA.js" ></head><body><div class="slide" id="slideX">
grrrrrrrr
>
</div></body></html>
>
Why is slideX coming up null?
>
I'm really tired, I've been working from noon to 9 pm yesterday and
from 1 am to 5 am this morning.

-Lost
Guest
 
Posts: n/a
#3: May 13 '07

re: getElementById driving me crazy


pantagruel wrote:
Quote:
ruel <rasmussen.br...@gmail.comwrote:
Quote:
>the browser is firefox
>>
>the javascript:
>>
>function slideshowchecker(){
>>
>if(document.getElementById){alert('it works');}
>slide = document.getElementById("slideX");
>>
>if(slide==null){
>alert('yes2');
>>
>}
>}
>>
>window.onload=slideshowchecker();
window.onload = slideshowchecker;

Don't use the call operator, when assigning functions to events.

If you need to pass the event:

window.onload = function(e) { alert('on' + e.type); }

If you need to pass arguments:

window.onload = function()
{
func1('arg1', 'arg2');
}
Quote:
Quote:
>the document has a div id = slideX.
>both alerts keep coming up.
>>
>here is the html
>>
><!DOCTYPE HTML PUBLIC
>"-//W3C//DTD HTML 4.01 Transitional//EN"
>"http://www.w3.org/TR/html4/loose.dtd">
><html><head><title>slideshow</title><script
>>
>src="jscripts/GTA.js" ></head><body><div class="slide" id="slideX">
>grrrrrrrr
>>
></div></body></html>
>>
>Why is slideX coming up null?
>>
>I'm really tired, I've been working from noon to 9 pm yesterday and
>from 1 am to 5 am this morning.
<attempt to fix top post>
Quote:
On May 13, 5:40 am, pantag
oh wait, just realized, the script is executing before the div exists
so slide is null.
What is "GTA.js?" I ask only because I am a Grand Theft Auto fanatic.
If it has something to do with that, you must share. :)

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
pantagruel
Guest
 
Posts: n/a
#4: May 15 '07

re: getElementById driving me crazy


Thanks for the help, no actually it isn't Grand Theft Auto, sorry.
Hmm, maybe I should reconsider my acronym.

Cheers,
Bryan Rasmussen

On May 13, 6:09 am, -Lost <maventheextrawo...@techie.comwrote:
Quote:
pantagruel wrote:
Quote:
ruel <rasmussen.br...@gmail.comwrote:
Quote:
the browser is firefox
>
Quote:
Quote:
the javascript:
>
Quote:
Quote:
function slideshowchecker(){
>
Quote:
Quote:
if(document.getElementById){alert('it works');}
slide = document.getElementById("slideX");
>
Quote:
Quote:
if(slide==null){
alert('yes2');
>
Quote:
Quote:
}
}
>
Quote:
Quote:
window.onload=slideshowchecker();
>
window.onload = slideshowchecker;
>
Don't use the call operator, when assigning functions to events.
>
If you need to pass the event:
>
window.onload = function(e) { alert('on' + e.type); }
>
If you need to pass arguments:
>
window.onload = function()
{
func1('arg1', 'arg2');
>
>
>
}
Quote:
Quote:
the document has a div id = slideX.
both alerts keep coming up.
>
Quote:
Quote:
here is the html
>
Quote:
Quote:
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head><title>slideshow</title><script
>
Quote:
Quote:
src="jscripts/GTA.js" ></head><body><div class="slide" id="slideX">
grrrrrrrr
>
Quote:
Quote:
</div></body></html>
>
Quote:
Quote:
Why is slideX coming up null?
>
Quote:
Quote:
I'm really tired, I've been working from noon to 9 pm yesterday and
from 1 am to 5 am this morning.
>
<attempt to fix top post>
Quote:
On May 13, 5:40 am, pantag
oh wait, just realized, the script is executing before the div exists
so slide is null.
>
What is "GTA.js?" I ask only because I am a Grand Theft Auto fanatic.
If it has something to do with that, you must share. :)
>
--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.

Closed Thread