Been a while I have a wonderment how facebook can create something that as cool as its status update. If you're unsure what I'm talking about maybe this will help you: every time you write your status and submit it, you will find the list of your feed moved slide down. I thought it was really cool! Then when I was working on my online application I accidentally thought about it again and suddenly I found the idea behind that cool feature. And here's how I do it..
Set the template
In order to make it works, we need to set up THE template which means I need to have THE form and (I call it) THE feed, which is a place to where the new status would beautifully appear.
THE FORM would look something like this
and THE FEED would look something like this<form action="javascript:void(0);">
<textarea name="status"></textarea><br />
<input type="button" name="update" value="update" />
</form><div class="the-feed" style="height: 100px; width: 300px; border:1px solid black;">
<ul>
<li>Last Feed</li>
</ul>
</div>Call / include jQuery
yup, I use jQuery to help me achiving this feature. and I used the one that Google kept on its server<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>Create THE SNIPPET/FUNCTION
Now this small snippet will handle the interactive update ala facebook
var interactiveUpdate = function(id,update) {
var idparam = '.'+ id + ' ul li:first-child';
// insert new list onto the first child of ul and hide it
$(idparam).before('<li style="display:none;">'+update+'</li>');
// display the hidden first child using jQuery's effect slideDown()
$(idparam).slideDown("slow");
}This snippet contains three important parameters: id, update, and ul.
- id : is the reference name of the class in the div form. In this case I use "example-status-1422" - just to make sure that the tag's class is unique.
- update : is the desired string to be inserted in THE FEED. You can use html tag if you want.
- ul or ol : if in THE LOG part you are using <ul> then in the javascript function you should also use ul or if you use <ol> then in the javascript function ol it is.
Prepare the function to generate the snippet
Using jQuery's rules, I made a function that will execute every time the "update" button is clicked. This function would look something like this
$(function(){updateStatus();});
var updateStatus = function() {
// Set the event if the button is clicked
$('input[name="update"]').click(function() {
// grab the status
var stat = $('textarea[name="status"]').val();
// call the interactiveUpdate snippet
interactiveUpdate('the-feed',stat);
});
}Putting everything altogether and.. DONE!
Let's try it, shall we... (try to type something in THE FORM and press the "update" button. then, keep an eye on THE FEED)
THE FORM:THE FEED:- Last Feed
This tutorial does not actually connect the snippet to the database and store the updated status. However, you can insert additional script that will send query using AJAX and display the status if the storing process is successful.
Download
All of these codes can be downloaded here. I have included jquery as well, so you can try it immediately once you have downloaded and unziped the package.
Compatibility
I have tested this technique using the following browsers:
- Google Chrome 3.0.195.27
- Firefox 3.5.3
- Opera 10.00
- Safari 4.0.3
- IE 8.0.6001
If you find any bug and/or the example does not work in any specific browser, please let me know :)
Disclaimer
This may not be the same with the one that Facebook has. It is just only one way to achieve it and there are number of ways how this feature can be done in more sophisticated manner. Thank you for reading.


21 Oct 2009
freelynx
757 views












pertamaxxxx……
mantaaabbb artikelnya, mikirnya sampe frustasi sambil cabutin jenggot yak…hehehe…
[Reply]
yudiacro Reply:
25 Oct 2009 at 10:12
@sinok elek, bacanya juga sambil cabutin jenggot nih dek hahaha..
@yudiacro, mr murray kan ga punya jenggot, apa yg mo dicabutin… kambing expresss?????…hahaha
[Reply]
asiiik…
bisa bikin sendiri.. makasih sob infonya.. berguna banget
[Reply]
yudiacro Reply:
22 Dec 2009 at 22:33
@fajarfaqih, sama2 Mas. Makasih sudah berkunjung.
Wah, Ilmu ane bertambah… jelasin Plus sama masuk Databes duunk… ane juga gy blajar dari trial and error about Jquery …
[Reply]
yudiacro Reply:
30 Mar 2010 at 14:22
@Hitori, iya nanti menyusul databasenya gan. Masih belum sempat update artikel lagi :)
artikelnya seru2.. euey
ayo tulis yg laennya.. ^_^
[Reply]
freelynx Reply:
16 Jul 2010 at 22:41
@thea, Makasih udah mampir n baca2 artikelnya… Sedang diusahakan untuk bisa nulis2 lagi. Doakan kami!! Chayo! :-)
luhar bihasa……………..sering” bikin artikel about programming mas”
[Reply]
bisa minta full source nya tidak? soalnya saya cba java scriptnya tdak jalan,,,trima kasih,,
[Reply]
freelynx Reply:
16 Jul 2010 at 22:38
@ayu, hmm.. tidak jalannya pas dimananya ya? pas di coba di step nomor 5 itu jalan gak? soalnya udah dites di beberapa browser baik2 aja. boleh tau web browser apa yang dipakai mbak ayu?.. sama-sama…
freelynx Reply:
28 Jul 2010 at 13:39
@ayu, kalau masih berminat dengan full source codenya bisa didownload disini.
Happy coding..
wuihh…
mantab mas… keren lah.
[Reply]
boz…kok saya ga bisa tampil di Last Feed pas saya klik update
gmn yah code lengkap nya
saya gabunginnya kyk gini:
var interactiveUpdate = function(id,update) {
var idparam = ‘.’+ id + ‘ ul li:first-child’;
// insert new list onto the first child of ul and hide it
$(idparam).before(”+update+”);
// display the hidden first child using jQuery’s effect slideDown()
$(idparam).slideDown(“slow”);
}
$(function(){updateStatus();});
var updateStatus = function() {
// Set the event if the button is clicked
$(‘input[name="update"]‘).click(function() {
// grab the status
var stat = $(‘textarea[name="status"]‘).text();
// call the interactiveUpdate snippet
interactiveUpdate(‘the-feed’,stat);
});
}
Last Feed
.example-the-feed-1422 ul li { list-style:none; padding: 5px; border-bottom: 1px solid grey; height: 25px; }
.example-the-feed-1422 ul li:first-child { background-color:#F6D2E3;}
tapi tetep ga bs jalan tuh boz
mohon bantuannya biar saya mengerti boz
thanks
[Reply]
freelynx Reply:
28 Jul 2010 at 13:35
@ades, ternyata ada mixed up antara kode untuk tutorial dengan untuk demonya. So sorry for this. But Thanx banget udah secara gak langsung ngingetin untuk ngecek lagi. Tulisan ini udah diupdate, dan kalau mau langsung coba di box sendiri bisa didownload disini.
Thanx again!