PDA

View Full Version : Switch content script (and more) help needed...



wildmac
05-20-2006, 08:29 AM
Hello,

I'm building something based on some mods of the Switch content scripts. basically, I am making a simple quiz, with the user clicking on true/false and having the correct answer and some text displayed. When the "button" is clicked on, it's background should change, and if the other one is then clicked, the previous one is reverted.

I have the showing and hiding of the answer working, but I can't get anything with the "buttons" working. I'm probably doing something massively wrong, but I'm just trying to build it based on what is working.

Here's the javascript code:


function setDisplay(objectID,state) {
var object = document.getElementById(objectID);
object.style.display = state;
object.style.background = state2;
}

function toggleDisplay(objectID) {
var object = document.getElementById(objectID);
state = object.style.display;
if (state == 'block')
object.style.display = 'none';
else if (state != 'block')
object.style.display = 'block';
}


function hideDisplay(objectID) {
var object = document.getElementById(objectID);
state = object.style.display;
if (state == 'block')
object.style.display = 'none';
}


function toggleBackground(objectID) {
var object = document.getElementById(objectID);
state2 = object.style.background;
if (state2 == 'url(bevel1.jpg)')
object.style.background = 'url(bevel2.jpg)';
else if (state2 != 'url(bevel2.jpg)')
object.style.background = 'url(bevel1.jpg)';
}



and here's the html where the code is being called:


<div class="question">
Numbness and tingling in the foot can be a cause for alarm.
</div>
<span class="true" id="button1" style="background:url(bevel1.jpg)" onclick="toggleDisplay('true1'); hideDisplay('false1'); toggleBackground('button1');" href="javascript:void('')">
True
</span>&nbsp;
<span class="false" id="button2" style="background:url(bevel1.jpg)" onclick="toggleDisplay('false1'); hideDisplay('true1'); toggleBackground('button2');" href="javascript:void('')">
False
</span>
<div class="rightanswer" id="true1" style="display:none">
Correct! With some conditions, these sensations may indicate nerve problems that need immediate medical attention.
</div>
<div class="wronganswer" id="false1" style="display:none">
Incorrect. With some conditions, these sensations may indicate nerve problems that need immediate medical attention.
</div>


The "toggleBackground" function is the one not working at all. Additionally, I would like it to be able to revert the other button at the same time, but I guess I might be able to do that the same way I am hiding the content, if I can get "toggleBackground" working...

help!

thanks!