Hi, i have a problem with a recursive function. I'm working on a php-ajax application, and i managed to create a div that pops-up and displays the message from DB server, and I wanted this box to gradually disappear after a few seconds, a bit like outlook does when you receive a mail.. my problem is that, if i declare the id of the layer everything works fine, but if i try and build a "generic" function - that is, passing the div-id into the function - it stops working I'm not a wizard in JS at all, so maybe some of you have a better idea of how to do this? here's the code and thank you for your help var n = 100; function opTimer() { /* id of the div is "updateMonitor" */ var obj = document.getElementById("updateMonitor"); if(n > 0){ obj.style.display=""; try { /* Mozilla */ obj.style.MozOpacity = n/100; } catch(e) { /* IE */ obj.style.filters.alpha.opacity = n; } setTimeout("opTimer()",40); n--; } else { obj.style.display="none" try { obj.style.MozOpacity = 1; } catch (e) { obj.style.filters.alpha.opacity=100; } n=100; } } Code (markup): in other words, the above works, this doesn't: var n = 100; function opTimer(divID) { var obj = document.getElementById("updateMonitor"); if(n > 0){ obj.style.display=""; try { obj.style.MozOpacity = n/100; } catch(e) { obj.style.filters.alpha.opacity = n; } setTimeout("opTimer(divID)",40); n--; } else { obj.style.display="none" try { obj.style.MozOpacity = 1; } catch (e) { obj.style.filters.alpha.opacity=100; } n=100; } } Code (markup):
sorry krt, that was a typo, i did mean to declare obj that way, and it still doesn't work... so: var n = 100; function opTimer(divID) { var obj = document.getElementById(divID); if(n > 0){ obj.style.display=""; try { obj.style.MozOpacity = n/100; } catch(e) { obj.style.filters.alpha.opacity = n; } setTimeout("opTimer(divID)",40); n--; } else { obj.style.display="none" try { obj.style.MozOpacity = 1; } catch (e) { obj.style.filters.alpha.opacity=100; } n=100; } } Code (markup): this one doesn't work, and i get no error message in the console or anything..
oh well, I solved the problem, in case anyone is interested, it works like this var n = 100; function opTimer(divID) { var obj = document.getElementById(divID); if(n > 0){ obj.style.display=""; try { obj.style.MozOpacity = n/100; } catch(e) { obj.style.filters.alpha.opacity = n; } setTimeout("opTimer('" + divID + "')",40); n--; } else { obj.style.display="none" try { obj.style.MozOpacity = 1; } catch (e) { obj.style.filters.alpha.opacity=100; } n=100; } } Code (markup): cheers