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">

Link to comment
Share on other sites

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">

Link to comment
Share on other sites

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')"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.