Jump to content

Built a simple image changing script, but it doesn't work


Recommended Posts

So, I built this code, and it doesn't work. Have I missed something?

 

<SCRIPT type="text/javascript">
function selector('glancej') {
	document.getElementById('glance').style.display='block';
	document.getElementById('front').style.display='none';
}
function selector('frontj') {
	document.getElementById('glance').style.display='none';
	document.getElementById('front').style.display='block';
}
</SCRIPT>

<SPAN onclick="selector('glancej');">GLANCE</SPAN>
<SPAN onclick="selector('frontj');">FRONT</SPAN>

<IMG alt="" class="glance" id="glance" src="glance.png">
<IMG alt="" class="front" id="front" src="front.png">

This is actually a better way to explain what I am trying to do:

 

<SCRIPT type="text/javascript">
function selector('glancej') {
	document.getElementById('glance') {style.display='block'};
	document.getElementById('front') {style.display='none'};
}
function selector('frontj') {
	document.getElementById('glance') {style.display='none'};
	document.getElementById('front') {style.display='block'};
}
</SCRIPT>

<SPAN onclick="selector('glancej');">GLANCE</SPAN>
<SPAN onclick="selector('frontj');">FRONT</SPAN>

<IMG alt="" class="glance" id="glance" src="glance.png">
<IMG alt="" class="front" id="front" src="front.png">

You havent actually explained anything of what you are trying to do..

From what I can see you have defined the selector function twice, neither of which will work.

You will need to create a single function that has the value passed into it, depending on the variable you need to action it.

Example:

function selection(obj) {
if (obj == 'string1') {
	alert('Whoa! String 1');
} else if (obj == 'string2') {
	alert('Oh, its string 2');
} else {
	alert('No string eh?');
}
}

Usage example: onclick="selection('string1')"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.