Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Onclick Issue with 2 separate functions

Status
Not open for further replies.

Saiman70

Technical User
Mar 5, 2009
10
IT
Hello EB
;)
I got this

<script type="text/javascript" language="JavaScript">

if (document.images) {
var su = new Image(); // for the inactive image
su.src = "photo1.jpg";
var gius = new Image(); // for the active image
gius.src = "photo.jpg";
}



function act() {
if (document.images)
document.images.giu.src = gius.src;
}

function inact() {
if (document.images)
document.images.giu.src = su.src;
}



</script>


.....<HTML>


<div class="box"> <a href="#" onClick="act()" onClick="inact();">
<img src="photo1.jpg" name="giu" border="0" alt="Netscent Advantages"></a></div>

The first function works, and show the image I want. (photo.jpg) when i clikc the mouse.
But if i want to return to the previous image, clicking again, It does not works

is there a part. reason? it seems correct?

bye
 
Hi

As far as I understand, it should work like a toggle button :
JavaScript:
function change()
{
  if (document.images)
  document.images.giu.src=document.images.giu.src==gius.src?su.src:gius.src;
}
HTML:
<a href="#" onclick="change()">

Feherke.
 
hi feherke

thanks for your help, it works greatly

just a question: I am noob and don't know the meaning of this second part of script

==gius.src?su.src:gius.src;

If you got time may you exp. the fundamentals?
and the ? what it is for?

thanks mate,
;)
paolo
 
That is called a ternary condition. It is the ability to write an if-else statement on one line.

Check out this article on Wikipedia about it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top