Build a dynamic select object using JSON on Facebook
Maybe if you are building a Facebook Aplicattion and you need to get the options from a JSON Response to create a select object, that post if for you.
The json response that we hace from our server server side is the next:
An that is the HTML and FBJS code (yeah, another way to hack Javascript) to build our object:
<div id="selectZone"></div>
<script type="text/javascript">
function buildObject(){
var ajax = new Ajax();
ajax.responseType = Ajax.JSON;
ajax.ondone = function(data){
select = document.createElement("select");
for(var i in data){
o = document.createElement("option");
o.setValue(i);
o.setTextValue(data[i]);
select.appendChild(o);
}
document.getElementById('selectZone').setTextValue('');
document.getElementById('selectZone').appendChild(select);
}
ajax.post('http://YOUR_URL/');
}
</script>
And that's all :).