Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
onclick within onclick?
Old 10-30-2010, 10:35 AM onclick within onclick?
miki86's Avatar
Extreme Talker

Posts: 184
Location: print_r($serbia);
Trades: 0
Im trying to run a function inside a function, both of them are triggered onmouseclick.
Problem is that the second function is triggered even though it's not clicked on that element which needs to trigger function2.

Example:
HTML Code:
<script type="text/javascript">
function1(itemID) {
     document.getElementById(itemID).style.visibility = "hidden";
     image2 = document.getElementById("image2");
     image2.style.visibility = "visible";
     
     image2.onclick = function2(); <!-- this is the problem -->
}
function2() {
     document.getElementById("image3").style.visibility = "visible";
}
</script>
html:
HTML Code:
<img src="#" id="image1" onclick="function1(this.id)"/>
<!-- HIDDEN BY DEFAULT -->
<img src="#" id="image2" />
<img src="#" id="image3" />
When clicked on image1, image2 should appear, and then when clicked on image2, image 3 should appear.

Not exactly what im working on but its gonna do as example.

Any way to solve this?
I know it can be done with separate functions but i need it to be like this.
miki86 is online now
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-30-2010, 12:29 PM Re: onclick within onclick?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Right now the script is trying to assign the return value of function2 to image.onclick. Try
Code:
image2.onclick = 'function2()';
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-30-2010, 01:19 PM Re: onclick within onclick?
miki86's Avatar
Extreme Talker

Posts: 184
Location: print_r($serbia);
Trades: 0
Yes that was it, it's also working without ()
Code:
image2.onclick = function2;
Question, can i pass variable to that function?
I tried with and without quotes but no luck.
miki86 is online now
Reply With Quote
View Public Profile
 
Old 10-30-2010, 01:27 PM Re: onclick within onclick?
miki86's Avatar
Extreme Talker

Posts: 184
Location: print_r($serbia);
Trades: 0
Never mind solved it like this:

Code:
var func = "function2("+var+")";
image2.onclick = func;
Thanks for your help.
miki86 is online now
Reply With Quote
View Public Profile
 
Old 11-01-2010, 12:25 PM Re: onclick within onclick?
miki86's Avatar
Extreme Talker

Posts: 184
Location: print_r($serbia);
Trades: 0
Ahh i still have problem with this.

Only works with opera like this:
Code:
image2.onclick = 'function2('+variable+')';
like this, its working with all browsers but it doesn't run onclick, it runs instantly
Code:
image2.onclick = function2(variable);
Working ok, but i need to pass that variable.
Code:
image2.onclick = function2;
Help?
miki86 is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to onclick within onclick?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.36317 seconds with 12 queries