ballouta Posted April 3, 2011 Share Posted April 3, 2011 Hello I am testing this script on firefox <script type="text/javascript"> function fnHide(oToHide){ window.setTimeout("fnHide2(" + oToHide.id + ")", 3000); } function fnHide2(sID){ var o = eval(sID); alert (o); o.style.display="none"; } </script> <input type="button" value="Count Down" id="oHideButton" onclick="fnHide(this)"> when I click the count down button, and after 3 seconds, the firebug shows this error message: oHideButton is not defined window.setTimeout("fnHide2(" + oToHide.id + ")", 3000); Please help thank you Quote Link to comment https://forums.phpfreaks.com/topic/232584-hide-a-button-after-3-seconds/ Share on other sites More sharing options...
nogray Posted April 3, 2011 Share Posted April 3, 2011 You are forgetting the quotes around the id string (since it's a string in the setimeout), this will fix it window.setTimeout("fnHide2('" + oToHide.id + "')", 3000); Quote Link to comment https://forums.phpfreaks.com/topic/232584-hide-a-button-after-3-seconds/#findComment-1196395 Share on other sites More sharing options...
ballouta Posted April 3, 2011 Author Share Posted April 3, 2011 Thanks now i have another error! oHideButton is not defined thank u very much Quote Link to comment https://forums.phpfreaks.com/topic/232584-hide-a-button-after-3-seconds/#findComment-1196396 Share on other sites More sharing options...
Adam Posted April 4, 2011 Share Posted April 4, 2011 You're trying to eval() just the ID - though I don't know why you're using it in the first place - which is causing the error. Replace it with document.getElementById(): function fnHide2(sID){ var o = document.getElementById(sID); o.style.display="none"; } Quote Link to comment https://forums.phpfreaks.com/topic/232584-hide-a-button-after-3-seconds/#findComment-1196572 Share on other sites More sharing options...
ballouta Posted April 4, 2011 Author Share Posted April 4, 2011 Thanks MrAdam ur code solved the problem actually this code is not mine, our instructor asked us to read handouts she posted, and i like this code function and wanted to test it then I had troubles with it, the code that you used is what we studied at college thank you Quote Link to comment https://forums.phpfreaks.com/topic/232584-hide-a-button-after-3-seconds/#findComment-1196689 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.