Skip to content

Instantly share code, notes, and snippets.

@twright
Created September 25, 2012 03:36
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 twright/3779840 to your computer and use it in GitHub Desktop.
Save twright/3779840 to your computer and use it in GitHub Desktop.
Combine images
jQuery(document).ready(function() {
// Add the event listainer to each field
addEventListeners('css selector of fields');
});
function changeSrc(img, url) {
// Set the src attribute of the image
image.attr('src', url);
}
function addEventListeners(fieldSelector) {
// Get all of the fields on the page
var fields = jQuery(fieldSelector);
// Add the relevant event listainer
fields.each(function(index) {
$(this).change(function() {
changeSrc($(this), getURLForImg($(this).val()));
});
});
}
function getURLForImg(fieldValue) {
// Get the url corresponding to the image
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment