Thursday, 22 August 2013

Extract SRC's from selected images, comma seperated

Extract SRC's from selected images, comma seperated

I'm using a Wordpress plugin where I can only type attachment urls (comma
seperated) in an input box. I need to alter the code so I can click an
image and it will extract the src to put it in the input box.
I made it possible with only one image.
First, I echo'd all the images from my media library. And then I did this:
<img class="media-image" src="<?php echo $images[$i]; ?>"/>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.media-image').click(function(){
var thisValue = jQuery(this).attr('src');
var thisTarget = jQuery('#target');
thisTarget.val(thisValue);
return false;
});
});
</script>
<input id="target" type="text"></input>
What this does: Whenever I click an image, the src will be put in the
input text box. When I click another image, the value will be changed
accordingly.
But how can I achieve this with multiple images? So, if I click 3 images,
I want all the src's to be comma seperated in the input field. Whenever I
click a selected image again, I want it to be deselected (i.e. I want the
src to be removed from the input).
Any ideas?

No comments:

Post a Comment