Freedom-n-Democrazy Posted October 3, 2011 Share Posted October 3, 2011 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"> Quote Link to comment https://forums.phpfreaks.com/topic/248307-built-a-simple-image-changing-script-but-it-doesnt-work/ Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 3, 2011 Author Share Posted October 3, 2011 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"> Quote Link to comment https://forums.phpfreaks.com/topic/248307-built-a-simple-image-changing-script-but-it-doesnt-work/#findComment-1275088 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 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')" Quote Link to comment https://forums.phpfreaks.com/topic/248307-built-a-simple-image-changing-script-but-it-doesnt-work/#findComment-1275153 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.