Xajax 0.2: Tips and Tricks: Disappearing Text






Xajax 0.2: Tips and Tricks: Disappearing Text

I am writing this because for a while now i have wanted to display a message saying 'user changes have been saved', then disappear. I searched all over and could not find anything. Also, i'm not so great with JavaScript. I finally kept beating my head against the wall until i got it, then i figured i would share it with the rest of you.


The following is the saved message code.

<div id="saveMessage" style="display:none;">
   <div align="center" class="form_text" style="color:#000000; background-color:#FFD363; font-weight:bold; display:block;">
   Changes have been saved
   </div>
</div>

Using xajax there are serveral options to show an object response. I utilize the addScript Response.

$objResponse->addScript("document.getElementById('saveMessage').style.display='inline'; 
            setTimeout(\"document.getElementById('saveMessage').style.display='none'\",1500); ");

That's It. Sorry it's not so much in detail. If you would like me to add to it or have any questions feel free to email me at nickbello@stoproductions.com

-Nick http://stoproductions.com


If you are calling from php, you can also use the sleep() function before calling $objResponse->addAssign("saveMessage","style.display","none");

-Caesare


Caesare... no you can't. The idea of this, is that the display is always set to none. The saved message is always on the page... just hidden. The javascript in one fell swoop will display it, then make it disappear. A.K.A. the sleep function has no place here.

-Nick http://stoproductions.com


Not to stop you from not applying your technique. Initially, the div is set to display:none, then when a change to the setting is made, whether db or file write, you would set the div to "block/inline", while you are doing your backend process. When that is done, you would only make the div back to display:none. By applying your technique, what would happen if the process was longer than 1500?



If the process was longer than 1500 it would just take more time to disappear. 1500 hundred is in milliseconds i think. so 1500 stands for 1.5 seconds. If you were to change it, it would disappear faster or slower based on whether or not you went up or down with the number.

-Nick http://stoproductions.com


May I ask if any error checking has been made? or, would the 'Changes have been saved' message be displayed without actual knowledge whether the database had indeed been updated?

As newbie to Javascript & x/Ajax I don't know if the following line has confirmation of success before displaying the message saying so...
$objResponse->addScript("document.getElementById('saveMessage').style.display='inline';

-pSouper


pSouper.... that is a coding question. Visit the xajax forum or a regular php forum. My example to display a disappearing element is just that, a way to display a disappearing element. The element can be anything included in the div tag that has the element name 'saveMessage'. It could even be an image. How you choose what goes in there and why it is displayed is up to you.

Like i said, visit the xajax forums for more programming questions. The wiki is designed to be an infobase, not a q&a.

-Nick http://stoproductions.com