Click to See Complete Forum and Search --> : Can anyone clarify this code for me?


Portmoon
02-26-2003, 06:42 AM
Hi there,

I wanted a piece of code that would grade my quiz program i.e Highlight the correct answer in each case.
I came across the following code and it works, the trouble is I don't know excactly what it is doing?? I have traced through the code a number of times but am no wiser to its actual purpose.
A brief synopsis of the functions below would be greatly appreciated.

Thanks,


function getStyleObject(objectId) {
// cross-browser function to get an object's style object given its id
if(document.getElementById && document.getElementById(objectId)) {
// W3C DOM
return document.getElementById(objectId).style;
} else if (document.all && document.all(objectId)) {
// MSIE 4 DOM
return document.all(objectId).style;
} else if (document.layers && document.layers[objectId]) {
// NN 4 DOM.. note: this won't find nested layers
return document.layers[objectId];
} else {
return false;
}
} // getStyleObject



function changeObjectVisibility(objectId, newVisibility) {
// get a reference to the cross-browser style object and make sure the object exists
var styleObject = getStyleObject(objectId);
if(styleObject) {
styleObject.visibility = newVisibility;
return true;
} else {
//we couldn't find the object, so we can't change its visibility
return false;
}
} // changeObjectVisibility



for (i=0 ; i<41 ; i++) {
var styleObject = getStyleObject('answer'+i);
if(styleObject) styleObject.background = colour;
}

Portmoon
02-26-2003, 10:11 AM
Thanks Dave,

So when the function is called it will highlight all the answers that are deemed 'correct'.
My quiz program has four answer possibilities and can be selected via radio buttons. When I call this function the correct answer is highlighted as is the corresponding radio button.
What determines that that specific area becomes highlighted?

Thanks!

Portmoon
02-27-2003, 02:25 PM
Thanks again Dave!!