Posts: 184
Location: print_r($serbia);
|
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.
|