Skip to content

Instantly share code, notes, and snippets.

@rmurphey
Created September 26, 2009 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmurphey/194346 to your computer and use it in GitHub Desktop.
Save rmurphey/194346 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
var $specials = $('#specials');
$specials.find('li.buttons').remove();
var cachedResponse = null;
var $details = $('<div/>').appendTo($specials);
var handleResponse = function(specials, val) {
var daySpecial = specials[val];
var html = '<h3>' + daySpecial.title + '</h3>';
html += '<p>' + daySpecial.text + '</p>';
$details.html(html);
$('<img/>')
.attr('src', daySpecial.image)
.appendTo($details);
$details.css('color', daySpecial.color);
};
var $select = $specials.find('select')
.change(function() {
var val = $select.val();
if (!val) {
$details.empty();
return;
}
if (cachedResponse) {
handleResponse(cachedResponse, val);
} else {
$.ajax({
type : 'get',
dataType : 'json',
url : 'json/specials.json',
success : function(specials) {
handleResponse(specials, val);
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment