Strac72 Posted September 12, 2011 Share Posted September 12, 2011 After much fizzling of brain and some help on here, I managed to get this script to do what I wanted: <td> <form name="input" action="motw.php" method="post"> <h4>Want a specific film? <input type="text" width="300" name="requests" /> <input type="submit" value="Request" /></h4> </form> <?php $requests = $_POST['requests']; $data = "$requests\n"; //open the file and choose the mode $fh = fopen("../filmoftheweek/users.txt", "a"); fwrite($fh, $data); fclose($fh); if (!empty ($_POST)) print "Ok, I'll see what I can do."; ?> </td> I would now like to make the echo/print disappear again after 10 seconds. Is there any way to do this? Thanks in advance, Paul Quote Link to comment https://forums.phpfreaks.com/topic/246951-getting-an-echo-to-disappear-after-10-seconds/ Share on other sites More sharing options...
marcelobm Posted September 12, 2011 Share Posted September 12, 2011 do you mean remove the message and stay with the form? Quote Link to comment https://forums.phpfreaks.com/topic/246951-getting-an-echo-to-disappear-after-10-seconds/#findComment-1268261 Share on other sites More sharing options...
Strac72 Posted September 12, 2011 Author Share Posted September 12, 2011 Yes, it's only a single text field, within a table, and the message comes up beneath the field on clicking the request button. It also writes to a text file but it would be nice if the message disappeared again after 10 seconds as there's plenty of other stuff on the page to look at and do. I just know that if you submit a form and get no message, users are wondering if anything has happened. Quote Link to comment https://forums.phpfreaks.com/topic/246951-getting-an-echo-to-disappear-after-10-seconds/#findComment-1268262 Share on other sites More sharing options...
Adam Posted September 12, 2011 Share Posted September 12, 2011 You would need to use JavaScript to dynamically remove the element after a period of time: <script type="text/javascript"> window.onload = function() { timedHide(document.getElementById('id_of_element'), 10); } function timedHide(element, seconds) { if (element) { setTimeout(function() { element.style.display = 'none'; }, seconds*1000); } } </script> If you have already defined an onload event handler, you'll need to merge this with the existing one. Moving to JS forum by the way. Quote Link to comment https://forums.phpfreaks.com/topic/246951-getting-an-echo-to-disappear-after-10-seconds/#findComment-1268265 Share on other sites More sharing options...
Strac72 Posted September 12, 2011 Author Share Posted September 12, 2011 There isn't an onload handler, that's the whole of the script here. I have no idea how to implement the javascript within it. It's a maybe a simple little thing but it took me about 8 hours to get that working from what I could glean from tutorials and help composing the php if statement from kind folk at the php forum. That's my level of expertise, I'm afraid! I am learning. This isn't for a public site. Quote Link to comment https://forums.phpfreaks.com/topic/246951-getting-an-echo-to-disappear-after-10-seconds/#findComment-1268270 Share on other sites More sharing options...
Adam Posted September 12, 2011 Share Posted September 12, 2011 Just add the script I posted in between the <head></head> tags, and change id_of_element to an ID attributed to the element you wish to hide. Quote Link to comment https://forums.phpfreaks.com/topic/246951-getting-an-echo-to-disappear-after-10-seconds/#findComment-1268274 Share on other sites More sharing options...
Strac72 Posted September 12, 2011 Author Share Posted September 12, 2011 Not to sound thick, but, how do I assign an ID to the element? it only exists as a print command: print "Ok, I'll see what I can do."; I did try adding it to the form, but I know that's not the right place on thinking a bit harder: <form name="input" action="motw.php" method="post"> <h4>Want a specific film? <input type="text" width="300" name="requests" id="message" /> <input type="submit" value="Request" /></h4> </form> I really don't know how to assign it Adam. I did try looking around on the net so as not to just have it all done for me, but to no avail! Quote Link to comment https://forums.phpfreaks.com/topic/246951-getting-an-echo-to-disappear-after-10-seconds/#findComment-1268284 Share on other sites More sharing options...
Adam Posted September 12, 2011 Share Posted September 12, 2011 print '<span id="desired_id_here">Ok, I\'ll see what I can do.</span>'; Quote Link to comment https://forums.phpfreaks.com/topic/246951-getting-an-echo-to-disappear-after-10-seconds/#findComment-1268288 Share on other sites More sharing options...
Strac72 Posted September 12, 2011 Author Share Posted September 12, 2011 Sorry, Adam. It just doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/246951-getting-an-echo-to-disappear-after-10-seconds/#findComment-1268320 Share on other sites More sharing options...
Strac72 Posted September 12, 2011 Author Share Posted September 12, 2011 I have ended up with this: <script type="text/javascript"> window.onload = function() { timedHide(document.getElementById('message'), 10); } function timedHide(element, seconds) { if (element) { setTimeout(function() { element.style.display = 'none'; }, seconds*1000); } } </script> </head> <body onload="MM_preloadImages('../images/buttons/downloadNeg.png')"> <div align="center"><img src="../cinema/motw_images/movie_download.png" width="378" height="182" /></div> <h3 align="center"><strong>This week's film is:</strong></h3> <h1 align="center"><strong>"Source Code"</strong></h1> <div align="center"> <a href="http://db.tt/XdFJgqM" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('downmotw','','../images/buttons/downloadNeg.png',1)"><img src="../images/buttons/download.png" name="downmotw" width="150" height="75" border="0" id="downmotw" /></a></div> <p align="center"><strong>If the file starts to play in your media player and you want to watch it later, right click the button and choose 'save as' or 'save link as'.</strong></p> <div align="center"> <table width="100%" border="0" cellspacing="10"> <tr> <td><h2 align="center"><strong><u>Description</u></strong></h2></td> <td> <form name="input" action="motw.php" method="post"> <h4>Want a specific film? <input type="text" width="300" name="requests" /> <input type="submit" value="Request" /></h4> </form> <?php $requests = $_POST['requests']; $data = "$requests\n"; $fh = fopen("../filmoftheweek/users.txt", "a"); fwrite($fh, $data); fclose($fh); if (!empty ($_POST)) print '<span id="message">Ok, I\'ll see what I can do.</span>'; ?> </td> Which leaves the message on the screen in Firefox, Chrome and IE. Haven't tested it on other browsers but I don't think it's that. Anybody got any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/246951-getting-an-echo-to-disappear-after-10-seconds/#findComment-1268418 Share on other sites More sharing options...
Adam Posted September 12, 2011 Share Posted September 12, 2011 You already have an onload event defined: onload="MM_preloadImages('../images/buttons/downloadNeg.png')" Move the function call into the anonymous function: window.onload = function() { MM_preloadImages('../images/buttons/downloadNeg.png'); timedHide(document.getElementById('message'), 10); } Quote Link to comment https://forums.phpfreaks.com/topic/246951-getting-an-echo-to-disappear-after-10-seconds/#findComment-1268429 Share on other sites More sharing options...
Strac72 Posted September 12, 2011 Author Share Posted September 12, 2011 You deserve the guru bit Adam! Thanks very much indeed. 8) I suppose I've learned 3 things today: 1. Always give out an entire script if asking for help. 2. Don't trust Fireworks generated code. 3. There are good folk in the online community who do it because they love it. Actually, make that 4; my distinction in Designing and creating advanced websites isn't worth the paper it's printed on. Cheers City & Guilds and Trowbridge college. Thanks again Adam. Quote Link to comment https://forums.phpfreaks.com/topic/246951-getting-an-echo-to-disappear-after-10-seconds/#findComment-1268446 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.