473,386 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Click twice for function execution

Hi.

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
  1. document.onclick = startMenuActions
  2.  
  3. var startMenuOn = false
  4. var clickedElement = "none"
  5.  
  6. function startOrbOnMouseOver() {
  7.  
  8. if (startMenuOn == false)
  9. {
  10. setBackground('startorb','url(http://willat8.freehostia.com/res/startorbon.png)')
  11. }
  12. }
  13.  
  14.  
  15. function startOrbOnMouseOut() {
  16.  
  17. if (startMenuOn == false)
  18. {
  19. setBackground('startorb','url(http://willat8.freehostia.com/res/startorboff.png)')
  20. }
  21. }
  22.  
  23.  
  24. function startMenuActions() {
  25.  
  26. document.getElementById("startmenu").onclick = function() {
  27. clickedElement = 'startmenu'
  28. }
  29. document.getElementById("startorb").onclick = function() {
  30. clickedElement = 'startorb'
  31. }
  32.  
  33. if (clickedElement == "startorb" && startMenuOn == false)
  34. {
  35. setBackground('startorb','url(http://willat8.freehostia.com/res/startorbclick.png)');setDisplay('startmenu','block');startMenuOn = true
  36. }
  37. else if (clickedElement == "startorb" && startMenuOn == true)
  38. {
  39. setBackground('startorb','url(http://willat8.freehostia.com/res/startorbon.png)');setDisplay('startmenu','none');startMenuOn = false
  40. }
  41.  
  42. if (clickedElement == "none")
  43. {
  44. setBackground('startorb','url(http://willat8.freehostia.com/res/startorboff.png)');setDisplay('startmenu','none');startMenuOn = false
  45. }
  46.  
  47. clickedElement = "none"
  48. }
Relevant HTML

Expand|Select|Wrap|Line Numbers
  1. <div id="startorb" onmouseover="startOrbOnMouseOver()" onmouseout="startOrbOnMouseOut()">
  2. </div>
Any help as to how I could make this function execute on the first click would be much appreciated.

Will.
Oct 25 '08 #1
2 4489
Dear Friend,

See what is happenong in your code on the first click the function is getting fired
i.e startMenuActions it is going in that parenthesis it is setting the function clickedElement = 'startmenu' on onclick of the div insted of firing the function in which clickedElement = 'startmenu' is there.

On second click the startMenuActions is getting fired then it is firing the function clickedElement = 'startmenu' .Thats why it is getting fired on the second click.

So you just directly check the condition that which is element is fired.Instead of assigning any function to it.
Oct 25 '08 #2
Dear Friend,

See what is happenong in your code on the first click the function is getting fired
i.e startMenuActions it is going in that parenthesis it is setting the function clickedElement = 'startmenu' on onclick of the div insted of firing the function in which clickedElement = 'startmenu' is there.

On second click the startMenuActions is getting fired then it is firing the function clickedElement = 'startmenu' .Thats why it is getting fired on the second click.

So you just directly check the condition that which is element is fired.Instead of assigning any function to it.
Thank you for your help Rsmastermind. Problem solved now :) (well, almost).
Oct 26 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: wendy | last post by:
I created com add-in for word2003, excel2003 and powerpoint2003, basically, i added 4 button in toobar and on_click, i apply some bussiness logic. all works in excel2003 and powerpoint 2003, but in...
1
by: SABmore | last post by:
I have the following code that populates 3 independent drop-down boxes with data from arrays. From there the user can select a value from a drop-down list, or input data into a text box. The user...
2
by: cschang | last post by:
I have a form containing a link next to an input box. I include a javascript function in the input by using the onblur='fuc()'. I used this function to open another ASP page to do something and...
1
by: zoltix | last post by:
Hi, I am beginner in JavaScript. I would like to intercept all click events on my document. I use this function for that document.onmousedown=click;. It works well. But I would like to...
6
by: Michael Johnson Jr. | last post by:
I am trying to handle a button click event, which updates a web control table with data. The button is dynamically created in the table itself. When I call updateTable() in the Page_Load the new...
4
by: surveyor04 | last post by:
Can someone help me try to figure out why my pages load twice? While debugging other issues, I notice that a great many of my pages run through the onload method twice, and sometimes they run...
0
by: Diffident | last post by:
Hello All, I have an asp:button and I have tied an eventhandler to this button's click event which means that the eventhandler should be executed everytime I click the button. But to my...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
2
by: =?Utf-8?B?SGV6YWw=?= | last post by:
Hi, I am trying to add a new record to a table but everytime I click the button, somehow it saves the record twice... I've created a stored procedure to insert records into a table and I called...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.