Friday, May 23, 2014

how to assign value one multiple select option to another multiple select option and remove using javascript



This may help you below Example:

 one select option value click to assign other select option.

 
<select name="avail_func" id="avail_func" size="5" style="width: 240px" multiple="multiple" >
<option value="65">Ac (American)</option>
<option value="40">AD (Infrastructures)</option>
<option value="71">Ae (Natural)</option>
</select>
<a href="javascript:void(0);" onclick="addFunc();">Add</a>
<a href="javascript:void(0);" onclick="delFunc();">Remove</a>
<select name="function_id[]" id="function_id" size="5" multiple="multiple" style="width: 240px" >
<option value="0">select one server</option>
</select>

<script>
function delFunc() {
                                var elm = document.getElementById('function_id');
                                while (elm.selectedIndex > -1) elm.options.remove(elm.selectedIndex);
                }
function addFunc() {
                                var elm1 = document.getElementById('avail_func');
                                var elm2 = document.getElementById('function_id');
                for (x=0;x<elm1.options.length;x++)
                 {
                  if(elm1.options[x].selected)
                     {


                           if (elm1.selectedIndex > -1)
                           {
                                   var new_id = elm1.options[x].value;
                                   var new_name =elm1.options[x].text;
                                   var alreadythere = false;
                                   for (i=0; i<elm2.options.length; i++)
                                        if (elm2.options[i].value == new_id)alreadythere = true;
                                        if (! alreadythere) elm2.add(new Option(new_name, new_id));

                            }

                     }
              }
                }

</script>

Sunday, April 27, 2014

How do I get album pictures using facebook API?

 
  1. From the first call you get all the albums (and the album IDs) '/me/albums'
  2. from there you can get the album picture (cover) '/'+album.id+'/picture'
  3. AND the photos of the album '/'+album.id+'/photos'
 
 
 FB.api("/"+albumid+"/photos",function(response){
    var photos = response["data"];
    document.getElementById("photos_header").innerHTML = "Photos("+photos.length+")";
    for(var v=0;v<photos.length;v++) {
        var image_arr = photos[v]["images"];

        var subImages_text1 = "Photo "+(v+1);

        //this is for the small picture that comes in the second column
        var subImages_text2 = '<img src="'+image_arr[(image_arr.length-1)]["source"]+'" />';

        //this is for the third column, which holds the links other size versions of a picture
        var subImages_text3 = "";

        //gets all the different sizes available for a given image
        for(var j = 0 ;j<image_arr.length;j++) {
            subImages_text3 += '<a target="_blank" href="'+image_arr[j]["source"]+'">Photo('+image_arr[j]["width"]+"X"+image_arr[j]["height"]+')</a><br/>';
        }
        addNewRow(subImages_text1,subImages_text2,subImages_text3);
    }
});