Javascript needing updated for ie8

I have the following javascript which works fine in IE7 but not in IE8. Inherited code and I'm a javascript novice, hence why i need the help. The code basically displays an overlayed div when a radio button list choice is selected. Code is actually run in an ASP.Net page.
// Get the position of an element
var x=0, y=0;
function getAbsElemPos(el) {
	var posX=0, posY=0;
	while (el!=null) {
		posX+=el.offsetLeft;
		posY+=el.offsetTop;
		el=el.offsetParent;
	}
	x=posX;
	y=posY;
}
//	
function eventDisplayWarning() {
    // set delay and only display if rb19 is default, only fire once
    setTimeout('closeMessage()',5000);
    var o=document.getElementById("msg");
    if (o) {
    	// make the message visible
        getAbsElemPos(document.getElementById("ctl00$phBody$rblQ18"));
    	o.style.top=y+'px';
    	o.style.left=x+'px';
		o.style.visibility='visible';
	} else {
		alert('Undefined message object');
	}
}
// Timeout functions
function closeMessage() {
    var o=document.getElementById("msg");
	if (o) {
		// hide the message
		o.style.visibility='hidden';
	} else {
		alert('Undefined message object');
	}
}
//
function eventDisplayWarningPause(e) {
	setTimeout('eventDisplayWarning()',350);
}
function insertElement(o) {
	// insert the msg div into the DOM
	var el='<div id="msg" class="bx"><p class="bxt">Please read the next question (Q19) and response options carefully.</p></div>';
	if (o && typeof HTMLElement!="undefined") {
		var r=o.ownerDocument.createRange();
		r.setStartBefore(o);
		var parsedHTML=r.createContextualFragment(el);
		o.parentNode.insertBefore(parsedHTML,o);
	} else {
		o.insertAdjacentHTML('beforeBegin',el);
	}
}
function connectEvents() {

    var fld = document.getElementsByName('ctl00$phBody$rblQ18');
	for (var i=0;i<fld.length;i++){

		if (i==1) { insertElement(fld[i]); } // choose a visible element as insertion point
		if (fld[i].addEventListener)
		{
		    fld[i].addEventListener('click',eventDisplayWarningPause,false);
		} else {
		    fld[i].attachEvent('onclick',eventDisplayWarningPause);
		}
	}
}


// run now
connectEvents();

Open in new window

suromaAsked:
Who is Participating?
 
suromaConnect With a Mentor Author Commented:
eventDisplayWarningPause to added to the radiobutton click in connectEvents. The problem is that in IIS8 the overlay div is not displayed.

The proceedure just runs when the page loads - connectEvents
0
 
Obadiah ChristopherConnect With a Mentor Commented:
What exactly is the problem that u r facing. Is it the overlay div doesn't get displayed?

U'll have to provide some more code

getAbsElemPos(el)

Where is this function called from?

Which is the function called onclick of the radiobutton
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.