View Single Post
Old 04-03-2010, 04:31 PM   #2 (permalink)
adamdecaf
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

There is a simple way to do this.

html4strict Code:
<select name="mydropdown" onchange="change_content(this.options[this.selectedIndex].value);">
  <option value="List">View as list</option>
  <option value="Show">View as slide-show</option>
</select>

javascript Code:
function change_content(id, element) {
  // alert(id);

  // Now that we have the id we can grab documents with an XHR or
  // just change the content here.
 
  // For example if _element_ is an ID from an HTML Element
  var elm = document.getElementById(element);

      elm.innerHTML = id;

  // Or...
  // Remember, IE doesn't support this function.
  var xhr = new XMLHttpRequest();
      xhr.open('GET', 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=' + encodeURIComponent(id), false);
      xhr.send(null);

  // Now just parse the json
  // You should use this script.
  // [url]http://json.org/json2.js[/url]
  var response = JSON.parse(xhr.responseText);

  // And then fill the element
  var n = 0, count = response.length;
  while (n < count) {
     elm.innerHTML += ....
     n++;
  }

}
__________________
My Site
adamdecaf is offline  
Reply With Quote