I'm having some problems with the execution of a javascript function trigged by clicking on a div. This only occurs if I have not clicked anywhere on the page since load: if it is the first thing I click then I start getting problems.
See the problem in action here: http://willat8.freehostia.com/
If you click on the startbutton in the bottom left hand corner before you do anything else you'll notice that nothing happens. If you click it again then the intended action occurs.
I'll include the code for those who can't access the website.
Javascript
Expand|Select|Wrap|Line Numbers
- document.onclick = startMenuActions
- var startMenuOn = false
- var clickedElement = "none"
- function startOrbOnMouseOver() {
- if (startMenuOn == false)
- {
- setBackground('startorb','url(http://willat8.freehostia.com/res/startorbon.png)')
- }
- }
- function startOrbOnMouseOut() {
- if (startMenuOn == false)
- {
- setBackground('startorb','url(http://willat8.freehostia.com/res/startorboff.png)')
- }
- }
- function startMenuActions() {
- document.getElementById("startmenu").onclick = function() {
- clickedElement = 'startmenu'
- }
- document.getElementById("startorb").onclick = function() {
- clickedElement = 'startorb'
- }
- if (clickedElement == "startorb" && startMenuOn == false)
- {
- setBackground('startorb','url(http://willat8.freehostia.com/res/startorbclick.png)');setDisplay('startmenu','block');startMenuOn = true
- }
- else if (clickedElement == "startorb" && startMenuOn == true)
- {
- setBackground('startorb','url(http://willat8.freehostia.com/res/startorbon.png)');setDisplay('startmenu','none');startMenuOn = false
- }
- if (clickedElement == "none")
- {
- setBackground('startorb','url(http://willat8.freehostia.com/res/startorboff.png)');setDisplay('startmenu','none');startMenuOn = false
- }
- clickedElement = "none"
- }
Expand|Select|Wrap|Line Numbers
- <div id="startorb" onmouseover="startOrbOnMouseOver()" onmouseout="startOrbOnMouseOut()">
- </div>
Will.