Click to See Complete Forum and Search --> : window.onfocus problem


rjusa
11-05-2003, 11:38 PM
I thought the following would be executed when the child window closes and returns to the parent.
Code is in the parent.

<script language="JavaScript"><!--

window.onFocus=sum(this.value)

function sum(objRef) {
var result = 0;
result += document.forms[0].CndnFBpc.value - 0;
result += document.forms[0].CndnSBpc.value - 0;
result += document.forms[0].CndnCFBpc.value - 0;
result += document.forms[0].CndnCSBpc.value - 0;
if (result > 100)
alert("Your allocation exceeds 100%, please check your distribution");
}//--></script>

What have I screwed up this time?

Thanks,
Ron

Charles
11-06-2003, 04:57 AM
<script type="text/javascript">
<!--
window.onfocus = function () {
var result = 0;
result += document.forms[0].CndnFBpc.value - 0;
result += document.forms[0].CndnSBpc.value - 0;
result += document.forms[0].CndnCFBpc.value - 0;
result += document.forms[0].CndnCSBpc.value - 0;
if (result > 100)
alert("Your allocation exceeds 100%, please check your distribution");
}
// -->
</script>

rjusa
11-06-2003, 07:07 AM
Thanks for your input. What happens is I return to the parent, if the % total exceeds 100 I get the messsage BUT the window keeps popping up ~6x, the system freezes and I have to use a cntrl+alt+del to regain use of my computer. Thoughts?

Thanks,
Ron

skriptor
11-06-2003, 07:22 AM
Hi,
after closing the alertbox focus goes to the parent window again und result is calculated again...

Try using a global variable to break th loop.

Good luck, skriptor