Jump to content

Hide a button after 3 seconds


ballouta

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/232584-hide-a-button-after-3-seconds/
Share on other sites

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";
}

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.