Jump to content

Onload Setfocus() Not Happening


Elemental

Recommended Posts

Hey Folks, I have the following javascript

<head><script type="text/javascript"><!--function setFocus(){document.getElementById("emailAdd").focus();}//--></script></head>

and this is my html

<body onload="setFocus()">..........<form>..... <input type="text" id="emailAdd" class="email" maxlength="45" /></form>

but it's not working on either FF, IE or Op (haven't tried Sf). I also have a script on the page that's for a text scroller but that's working fine. I ran it through DebugBar and it fired correctly so I'm thinking it's the scroller script that's making it bug outHere's the script:

<div id="marqueecontainer"><div id="vmarquee"><!-- ****************************************************** Quotes //--><script type="text/javascript"> //<![CDATA[var scrollerwidth="280px"var scrollerheight="160px"var scrollerspeed="1" // Scrollers content goes here! Keep all of the message on the same line! var scrollercontent='<span class="quotes">"The purpose of relationship is not to have another who might complete you, but to have another with whom you might share your completeness."</span><span class="authors">~ Neale Donald Walsch ~</span><br /><br /><div class="separator"></div><br /><br /><span class="quotes">"Everything that irritates us about others Can lead us to an understanding of ourselves."</span><span class="authors">~ Carl Jung, Psychologist ~</span><br /><br /><div class="separator"></div><br /><br /><span class="quotes">"The worst thing you can possibly do is worry about what you could have done."</span><span class="authors">~ Author Unknown ~</span><br /><br /><div class="separator"></div><br /><br /><span class="quotes">"Every intention sets energy into motion Whether you are conscious of it or not."</span><span class="authors">~ Gary Zukav ~</span><br /><br /><div class="separator"></div><br /><br /><span class="quotes">"Go confidently In the direction of your Dreams. Live the life you\'ve imagined!"</span><span class="authors">~ Henry David Thoreau ~</span><br /><br /><div class="separator"></div><br /><br /><span class="quotes">"Unless you start doing something different, you are in for more of the same."</span><span class="authors">~ Author Unknown ~</span><br /><br /><div class="separator"></div><br /><br /><span class="quotes">"Regrets can hold you back and prevent the most wonderful things taking place in our lives."</span><span class="authors">~ Author Unknown ~</span><br /><br /><div class="separator"></div><br /><br /><span class="quotes">"The real voyage of discovery consists not in seeing new landscapes, but in having new eyes."</span><span class="authors">~ Marcel Proust ~</span><br /><br /><div class="separator"></div><br /><br /><span class="quotes">"We do not see things as they are. We see them as we are."</span><span class="authors">~ The Talmud ~</span><br /><br /><div class="separator"></div><br /><br /><span class="quotes">"What you love, you empower, and what you fear, you empower, and what you empower, you attract."</span><span class="authors">~ Author Unknown ~</span><br /><br /><div class="separator"></div><br /><br /><span class="quotes">"The truth will set you free. But first, it will piss you off."</span><span class="authors">~ Gloria Steinem ~</span>'var pauseit=1 // Change nothing below! scrollerspeed=(document.all)? scrollerspeed : Math.max(1, scrollerspeed-1) //slow speed down by 1 for NS var copyspeed=scrollerspeed var iedom=document.all||document.getElementById var actualheight=''var cross_scroller, ns_scroller var pausespeed=(pauseit==0)? copyspeed: 0 function populate(){if (iedom){cross_scroller=document.getElementById? document.getElementById("iescroller") : document.all.iescrollercross_scroller.style.top=parseInt(scrollerheight)+8+"px"cross_scroller.innerHTML=scrollercontentactualheight=cross_scroller.offsetHeight}else if (document.layers){ns_scroller=document.ns_scroller.document.ns_scroller2ns_scroller.top=parseInt(scrollerheight)+8ns_scroller.document.write(scrollercontent)ns_scroller.document.close()actualheight=ns_scroller.document.height}lefttime=setInterval("scrollscroller()",30)}window.onload=populate function scrollscroller(){ if (iedom){if (parseInt(cross_scroller.style.top)>(actualheight*(-1)+8))cross_scroller.style.top=parseInt(cross_scroller.style.top)-copyspeed+"px"elsecross_scroller.style.top=parseInt(scrollerheight)+8+"px"}else if (document.layers){if (ns_scroller.top>(actualheight*(-1)+8))ns_scroller.top-=copyspeedelsens_scroller.top=parseInt(scrollerheight)+8}} if (iedom||document.layers){with (document){if (iedom){write('<div style="position:relative;width:'+scrollerwidth+';height:'+scrollerheight+';overflow:hidden" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed">')write('<div id="iescroller" style="position:absolute;left:0px;top:0px;width:100%;">')write('</div></div>')}else if (document.layers){write('<ilayer width='+scrollerwidth+' height='+scrollerheight+' name="ns_scroller">')write('<layer name="ns_scroller2" width='+scrollerwidth+' height='+scrollerheight+' left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed"></layer>')write('</ilayer>')}}}//]]></script><!-- end scroll script ************************************************** //--></div></div>

Peace,Elemental

Link to comment
Share on other sites

The scroller script has this line: window.onload=populate - so it looks like the onload in the body tag is being reassigned. You'd need to replace that line so both functions are run.

Link to comment
Share on other sites

That is, delete that line from your scroller script, delete the onload statement from your body tag (you don't want javascript there anyway), and add this to your main script:

window.onload = function () {   populate();   setFocus();}

I did not study the doc closely enough to see if the sequence of those two statements matters. If weird stuff happens, try reversing the sequence.

Link to comment
Share on other sites

That is, delete that line from your scroller script, delete the onload statement from your body tag (you don't want javascript there anyway), and add this to your main script:
window.onload = function () {   populate();   setFocus();}

I did not study the doc closely enough to see if the sequence of those two statements matters. If weird stuff happens, try reversing the sequence.

Synook, Deirdre's Dad, Thank you both for your reply, much appreciated.Thank for telling me, 'Dude, you need to get some sleep, this 4 or 5 hours a night thing ain't good for you.'I saw the populate() call whe I ran it through DebugBar. Saw it, it's the first of two, and it din't register. Thanks guys, I'm going back to bed now.Peace,Elemental
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...